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

feat: handle virtual spaces when inserting code to cursor position #675

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ege0zcan
Copy link
Contributor

Desription

Adds the ability to handle virtual spaces to chat server

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ege0zcan ege0zcan force-pushed the virtualSpaces branch 2 times, most recently from e25f719 to 50cbdd1 Compare December 17, 2024 12:24
}

let textWithIndent = ''
params.code.split('\n').forEach((line, index) => {
if (index === 0) {
if (hasVirtualSpace) {
textWithIndent += indent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to Line 233, if the first line is blank, it shouldn't receive indentations. (Can this also be added as a test case please?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression that in the case of a virtual space we actually need this extra indent.

For a regular insertion (no virtual spaces) we don't add any indentation on the first line since the expectation is to insert the code block at the current cursor position and adding an indentation to the insertion would break the expectation

However, in the case of virtual spaces, the cursor might appear to the user at a certain position due to virtual spaces (e.g., 4 virtual spaces on a line, with the server receiving the cursor position as character 4). In this situation, the server must convert the virtual indentation into a real indentation when inserting the content into the file.

This is what the line in question achieves. To ensure the indentation is applied correctly, the server adjusts the cursor position to character 0 on line 222, so that the real spaces are inserted at the beginning of the line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an arbitrary example for illustrative purposes. My comment above refers to line 81 in the sample image, but I have provided a complete representation of the desired outcome. It's a corner case where the first line is blank - generally this should be uncommon.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants