-
Notifications
You must be signed in to change notification settings - Fork 142
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(editor): indent selected text on TAB key event #482
Conversation
Converting this to a draft. Will make it "ready for review" once this feature is implemented. |
editor/src/main/java/io/github/rosemoe/sora/widget/EditorKeyEventHandler.java
Outdated
Show resolved
Hide resolved
editor.getSnippetController().shiftToNextTabStop(); | ||
} else if (editor.getProps().indentSelectionWithTab) { | ||
editor.indentSelection(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing fallback case for inserting the TAB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will fix this.
if ("\t".equals(insertText[finalI])) { | ||
if (editor.getSnippetController().isInSnippet()) { | ||
editor.getSnippetController().shiftToNextTabStop(); | ||
} else if (editor.getProps().indentSelectionWithTab) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional conditions as above should be added here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't get this. What do you mean by "additional conditions as above" (the single line thing?)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the ambiguous statement. I mean additional check for if text is selected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, okay. I'll add it.
What do you think of these two choices?
One of the second choice's benefits is that if the line is not currently at an aligned stop (not at 1xtabWidth, 2xtabWidth, 3xtabWidth, ...), we could (if we need) give it a final Also, another benefit is being able to move the selection to the start of the line. With option 1, if it's not already aligned with a multiple of tabWidth, we could not do this. |
The configuration from language (useTab character) and editor tab width should also be considered when indenting/unindenting the texts. |
In vscode, SHIFT + TAB actually deletes leading space to align the indentation to nearest KxTabwidth. |
The point of my previous post's concern was making sure it could (and should) finally arrive at the start of the line. If the point was about whether we should align the line to a tab stop first (the same as VSCode as you mentioned) or right before reaching the start of the line, then yes, I agree that doing it first is better. Another thing is when we say to the "nearest" KxTabWidth, it should mean "nearest on the left," correct? Otherwise, we might never reach the start of the line. When doing a regular |
Yes. |
Only in the un-indentation, right? I'll work on suggestions posted here. But just to be sure, are the following statements correct? If not, please specify the expected behavior.
Should the current behavior be preserved (i.e. should I add a property to toggle between the current behavior and the new behavior)? |
Let me try my best to summarize what we have so far. Example:
With new behavior: 1 time
2 times
or,
2 times
3 times
4 times
With old behavior (make sure the selection is able to arrive at the left edge): 1 time
2 times
or,
2 times
3 times
4 times
The new behavior should be the default as more users might prefer it. @itsaky What I have in mind is this.
|
4 times case should be:
|
Yes, this happens in un-indentation.
All right.
Don't have to preserve I think. |
Shouldn't we keep the selected text's original formation and stop moving as soon as at least 1 line reaches the start of the line? I guess we could continue until everything has aligned with the left edge. However, the user needs to be careful not to accidently press even one too many If we could save the formation on a |
At least, vscode will continue to reduce the indentation. |
Okay, thanks for the confirmation.
Okay.
We can't know which line's indentation must be preserved unless we ask the language implementations to provide this information (which will be slow as the languages might need to analyze the source code). However, the |
The behavior has been updated according to the suggestions provided here. Here is a video demonstrating the same : VID_20230919194123.mp4Also, the |
This adds the ability to indent selected text when the
TAB
key is pressed. The feature can be enabled/disabled usingDirectAccessProps.indentSelectionWithTab
.Related issue : AndroidIDEOfficial/AndroidIDE#1229
Current behavior
Record_2023-09-07-12-09-19.mp4
New behavior
Record_2023-09-07-12-07-56.mp4