Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: Incorrect editor.selection Object in Jupyter Notebooks #14475

Closed
garyb9 opened this issue Nov 18, 2024 · 5 comments · Fixed by #14480
Closed

Issue: Incorrect editor.selection Object in Jupyter Notebooks #14475

garyb9 opened this issue Nov 18, 2024 · 5 comments · Fixed by #14480
Assignees
Labels
bug bugs found in the application notebook issues related to notebooks

Comments

@garyb9
Copy link

garyb9 commented Nov 18, 2024

Description:

When working with a Jupyter Notebook in Theia and using the vscode.window.activeTextEditor API to retrieve the editor.selection object, the selection data appears to be incorrect. This behavior differs from the expected results in VS Code.

Steps to Reproduce:
1. Open a Jupyter Notebook in Theia.
2. Select two lines of text within a single cell.
3. Log the editor.selection object:

const editor = vscode.window.activeTextEditor;
console.log('selection:', editor.selection);

Note - this only happens when selecting bottom to top

Expected Behavior (VS Code):

When selecting two lines in a cell, the editor.selection object accurately reflects the range, as shown below:

{
  "start": {
    "line": 1,
    "character": 0
  },
  "end": {
    "line": 2,
    "character": 9
  },
  "active": {
    "line": 1,
    "character": 0
  },
  "anchor": {
    "line": 2,
    "character": 9
  }
}

Observed Behavior (Theia):

For the same file and same selection, the editor.selection object is incorrect and outputs:

[
  {
    "line": 1,
    "character": 1
  },
  {
    "line": 1,
    "character": 1
  }
]

Attaching a screenshot of the ipynb file (notice the two highlighted lines):
image

The selection object does not reflect the correct range and appears to always point to a single character, regardless of the actual selection.

Impact:

This inconsistency affects extensions or code relying on the editor.selection API for Jupyter notebooks, leading to incorrect behavior or functionality.

Additional Context:

This issue appears specific to Jupyter notebooks and does not occur with standard text files. It might be related to how Theia handles notebook-specific editors versus standard text editors.

Request:

Please investigate this discrepancy and align the behavior of editor.selection in Jupyter notebooks with the expected behavior in VS Code.

@jonah-iden
Copy link
Contributor

Oh interesting. When selecting from top to bottom it works fine. But selecting bottom-top it just sets the cursor position. Are you encountering it the same way?
I'll see if i can fix it tommorrow

@garyb9
Copy link
Author

garyb9 commented Nov 18, 2024

@jonah-iden you're correct, i usually select from right to left, bottom up so i didnt notice it only happens in this direction

i will update the ticket then

@garyb9
Copy link
Author

garyb9 commented Nov 18, 2024

i have also updated this issue accordingly -
#14476

@garyb9
Copy link
Author

garyb9 commented Nov 18, 2024

although this one -
#14477

is unrelated to the direction of select and happens regardless

@jonah-iden
Copy link
Contributor

already found the issue and fixed it. Will look at the other two and probably create a single PR for all three

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bugs found in the application notebook issues related to notebooks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants