Skip to content

Commit

Permalink
Fixes "replace selection" behavior when nothing is selected (#251)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JasonWeill authored Jul 5, 2023
1 parent f4389f6 commit b62c816
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/jupyter-ai/src/selection-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b62c816

Please sign in to comment.