From 8566fcc2cfc57077cb276bc17dcb4730ea1844f1 Mon Sep 17 00:00:00 2001 From: Urtsi Santsi Date: Mon, 23 Oct 2023 07:06:27 +0300 Subject: [PATCH 1/2] If formatting produced the same text, ignore it. --- src/window.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/window.js b/src/window.js index 6a7a40610..5d7e4378e 100644 --- a/src/window.js +++ b/src/window.js @@ -197,12 +197,14 @@ export default function Window({ application, session }) { return; } + if (buffer.text === code) { + return; + } + const { cursor_position } = buffer; code_view.replaceText(code, false); buffer.place_cursor(buffer.get_iter_at_offset(cursor_position)); - - return code; } function formatRustCode(text) { From 85ec8100354bdeb3ccf0438f21512d689967d358 Mon Sep 17 00:00:00 2001 From: Urtsi Santsi Date: Mon, 23 Oct 2023 07:11:07 +0300 Subject: [PATCH 2/2] Format and set xml only if it is selected --- src/PanelUI.js | 5 +++++ src/window.js | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/PanelUI.js b/src/PanelUI.js index d3c62534d..0b1ac6d91 100644 --- a/src/PanelUI.js +++ b/src/PanelUI.js @@ -142,6 +142,10 @@ export default function PanelUI({ } } + function is_xml_selected() { + return lang === lang_xml; + } + const dropdown_selected_signal = listenProperty( dropdown_ui_lang, "selected", @@ -194,6 +198,7 @@ export default function PanelUI({ panel.start = start; panel.stop = stop; panel.update = update; + panel.is_xml_selected = is_xml_selected; panel.panel = panel_ui; return panel; diff --git a/src/window.js b/src/window.js index 5d7e4378e..1e05a8728 100644 --- a/src/window.js +++ b/src/window.js @@ -262,9 +262,11 @@ export default function Window({ application, session }) { } if (panel_ui.panel.visible) { - await format(langs.xml.document.code_view, (text) => { - return xml.format(text, 2); - }); + if (panel_ui.is_xml_selected()) { + await format(langs.xml.document.code_view, (text) => { + return xml.format(text, 2); + }); + } } }