From b62c8160f8e078fe8f7145be4d12c7982d9eafdb Mon Sep 17 00:00:00 2001 From: Jason Weill <93281816+JasonWeill@users.noreply.github.com> Date: Wed, 5 Jul 2023 15:28:29 -0700 Subject: [PATCH] Fixes "replace selection" behavior when nothing is selected (#251) * Check that selection has text before replacing * Disable replaceSelection if nothing is selected * Reverts changes to chat.tsx, modifies selection-watcher per @dlqqq * Update chat.tsx Removes unneeded comment --- packages/jupyter-ai/src/selection-watcher.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/jupyter-ai/src/selection-watcher.ts b/packages/jupyter-ai/src/selection-watcher.ts index 031fe8863..1ff5d4adc 100644 --- a/packages/jupyter-ai/src/selection-watcher.ts +++ b/packages/jupyter-ai/src/selection-watcher.ts @@ -58,6 +58,11 @@ function getTextSelection(widget: Widget | null): Selection | null { .getSource() .substring(startOffset, endOffset); + // Do not return a Selection object if no text is selected + if (!text) { + return null; + } + // ensure start <= end // required for editor.model.sharedModel.updateSource() if (startOffset > endOffset) {