From d7d4003b70f85e3bc11047714bb0c427194603a7 Mon Sep 17 00:00:00 2001 From: Rosemoe <2073412493@qq.com> Date: Thu, 30 Jan 2025 19:22:25 +0800 Subject: [PATCH] fix(editor): symbol completion is conflict with search replace (fix #638) --- .../github/rosemoe/sora/widget/CodeEditor.java | 16 ++++++++++++++-- .../rosemoe/sora/widget/EditorSearcher.java | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/editor/src/main/java/io/github/rosemoe/sora/widget/CodeEditor.java b/editor/src/main/java/io/github/rosemoe/sora/widget/CodeEditor.java index 7e14b0a3..60593abf 100644 --- a/editor/src/main/java/io/github/rosemoe/sora/widget/CodeEditor.java +++ b/editor/src/main/java/io/github/rosemoe/sora/widget/CodeEditor.java @@ -1874,16 +1874,28 @@ public void commitText(CharSequence text) { /** * Commit text at current state from IME * - * @param text Text commit by InputConnection + * @param text Text commit by InputConnection + * @param applyAutoIndent Apply automatic indentation */ public void commitText(CharSequence text, boolean applyAutoIndent) { + commitText(text, true, true); + } + + /** + * Commit text with given options + * + * @param text Text commit by InputConnection + * @param applyAutoIndent Apply automatic indentation + * @param applySymbolCompletion Apply symbol surroundings and completions + */ + public void commitText(CharSequence text, boolean applyAutoIndent, boolean applySymbolCompletion) { if (text.length() == 0) { return; } // replace text SymbolPairMatch.SymbolPair pair = null; - if (getProps().symbolPairAutoCompletion && text.length() > 0) { + if (applySymbolCompletion && getProps().symbolPairAutoCompletion && text.length() > 0) { var endCharFromText = text.charAt(text.length() - 1); char[] inputText = null; diff --git a/editor/src/main/java/io/github/rosemoe/sora/widget/EditorSearcher.java b/editor/src/main/java/io/github/rosemoe/sora/widget/EditorSearcher.java index 31cdac0f..bc557202 100644 --- a/editor/src/main/java/io/github/rosemoe/sora/widget/EditorSearcher.java +++ b/editor/src/main/java/io/github/rosemoe/sora/widget/EditorSearcher.java @@ -299,7 +299,7 @@ public void replaceCurrentMatch(@NonNull String replacement) { if (replacement.isEmpty()) { editor.deleteText(); } else { - editor.commitText(replacement); + editor.commitText(replacement, false, false); } } else { gotoNext();