fix: monaco editor glitches fixed
This commit is contained in:
@@ -26,6 +26,20 @@ export const MonacoEditor = {
|
||||
|
||||
const value = this.textarea.value || "";
|
||||
|
||||
// ponytail: ignore the server echoing back our own last-emitted value;
|
||||
// only a genuinely remote value (translation switch, etc.) should reset
|
||||
// the editor. Otherwise mid-typing echoes clobber the cursor to offset 0.
|
||||
if (value === this.lastKnownValue) {
|
||||
return;
|
||||
}
|
||||
|
||||
// While the user is actively typing, Monaco owns the content. Never let a
|
||||
// server re-render (autosave, dirty toggle, metadata) yank it out from
|
||||
// under the cursor — reconcile only once the editor is blurred.
|
||||
if (this.editor.hasTextFocus()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.editor.getValue() !== value) {
|
||||
this.isApplyingRemoteUpdate = true;
|
||||
this.editor.setValue(value);
|
||||
|
||||
@@ -82,6 +82,15 @@ defmodule BDS.Desktop.ShellLive.PostEditor do
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
def update(%{action: :auto_save} = assigns, socket) do
|
||||
socket =
|
||||
socket
|
||||
|> assign(Map.drop(assigns, [:action]))
|
||||
|> do_save(true)
|
||||
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
def update(%{action: :publish} = assigns, socket) do
|
||||
socket =
|
||||
socket
|
||||
@@ -451,7 +460,7 @@ defmodule BDS.Desktop.ShellLive.PostEditor do
|
||||
end
|
||||
end
|
||||
|
||||
defp do_save(socket) do
|
||||
defp do_save(socket, keep_draft? \\ false) do
|
||||
post = socket.assigns.post
|
||||
|
||||
case post do
|
||||
@@ -468,10 +477,19 @@ defmodule BDS.Desktop.ShellLive.PostEditor do
|
||||
refreshed_post = Posts.get_post!(post.id)
|
||||
_refreshed_form = persisted_form(refreshed_post, metadata, active_language)
|
||||
|
||||
# Autosave keeps the working draft so the live editor stays the source
|
||||
# of truth; only an explicit save drops it and reloads canonical body.
|
||||
drafts =
|
||||
if keep_draft? do
|
||||
socket.assigns.drafts
|
||||
else
|
||||
Map.delete(socket.assigns.drafts, active_language)
|
||||
end
|
||||
|
||||
socket =
|
||||
socket
|
||||
|> assign(:post, refreshed_post)
|
||||
|> assign(:drafts, Map.delete(socket.assigns.drafts, active_language))
|
||||
|> assign(:drafts, drafts)
|
||||
|> assign(:save_state, save_state_for_action(:save))
|
||||
|> assign(:dirty?, false)
|
||||
|> build_data()
|
||||
|
||||
@@ -18,7 +18,7 @@ defmodule BDS.Desktop.ShellLive.TabActions do
|
||||
%{assigns: %{current_tab: %{type: :post, id: post_id}, workbench: workbench}} = socket
|
||||
) do
|
||||
if Workbench.dirty?(workbench, :post, post_id) do
|
||||
Phoenix.LiveView.send_update(PostEditor, id: "post-editor-#{post_id}", action: :save)
|
||||
Phoenix.LiveView.send_update(PostEditor, id: "post-editor-#{post_id}", action: :auto_save)
|
||||
end
|
||||
|
||||
socket
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user