From 2f7ce4dd5011d6cd3cd187a627b03e93d5e1a74b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Szab=C3=B3?= Date: Tue, 18 Jul 2023 16:37:31 +0200 Subject: [PATCH] Add explicit replaceSelection() implementation The $.textSelection() facade in CodeEditor is missing a replaceSelection() implementation. This causes $.textSelection() to fall back to a naive implementation, which does not work, thus breaking any gadget or extension that tries to interact with CodeEditor using this method. As a fix, provide a native replaceSelection() implementation that calls the appropriate ACE editor method: Bug: T342127 Change-Id: Ie3ed681b39c5d4d2bed50030a397a2b1c877c9fb --- modules/jquery.codeEditor.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/jquery.codeEditor.js b/modules/jquery.codeEditor.js index c1d08b53..d4d6da9d 100644 --- a/modules/jquery.codeEditor.js +++ b/modules/jquery.codeEditor.js @@ -733,6 +733,16 @@ return context.codeEditor.getCopyText(); }, + /** + * Replace the current selection with the given text. + * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead + * + * @param {string} text + */ + replaceSelection: function ( text ) { + context.codeEditor.insert( text ); + }, + /** * Inserts text at the begining and end of a text selection, optionally inserting text at the caret when * selection is empty.