Skip to content

[🚫 Bug] TextEditor.selectText() considers tabs as 1 character istead of the equivalent number of spaces when trying to select a piece of code #2033

@Jokeswar

Description

@Jokeswar

Describe the bug

When trying to select a piece of code on a line by using the TextEditor.selectText('textExample'), the implementation gets the first line of text that has textExample and then looks for the starting index of the textExample string by using the String.indexOf() API (See this).

This is a problem because it considers each character to have a representation of length 1. This is not true in the case of tab characters (\t), which in VS Code can represent any number of whitespaces (the default is 4).
This assumption results in a wrong computation of the column index, which will fall short of what the moveCursor function checks when looking in the status bar.

The API should treat tabs as if they were whitespaces and take into account the indentation level. For example, if the indentation level is 2 spaces, it should consider them as such.

Steps to reproduce

1. File data:
Lorem ipsum
		textExample
Lorem ipsum

2. Code Snippet:
            await app.workbench.openFile('file.example');
            const textEditor = new TextEditor();
            await textEditor.selectText('textExample');

3. Expected result: `textExample` is selected
4. Actual result: Error is thrown: `Column number 2 is not accessible on line 2`. The actual column computed should have been 8 (due to having 2 \t characters - one tab is equivalent to 4 spaces)

Logs

NA

Operating System

Ubuntu 22.04

Visual Studio Code

1.93.1

vscode-extension-tester

8.7.0

NodeJS

20.15.1

npm

10.7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    Status

    Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions