editor: Fix auto-closing quotes after word character (#26803)
Closes #14349 When typing quotes immediately after a word character, it resulted in auto-closing the quote. ```js const thing = this is text^; ``` Typing a quote resulted in `this is text""^;` which is not correct, and should be `this is text"^;`. This PR changes logic for auto close: 1. We now prevent auto-closing in case of brackets where start == end when they're typed immediately after a word character. i.e. For, ``` `, ", ' ```. 2. Other bracket pairs like `{}, (), etc` continue to auto-close regardless of preceding character. So, `func^` to `func()^` will keep working. 3. Auto-closing in other contexts like after spaces, punctuation, etc. will still work. Before:  After:  Release Notes: - Fixed auto-paired quotes being inserted when typing a quote immediately next to a word character.
This commit is contained in:
parent
f40b22c02a
commit
3ad9074e63
2 changed files with 32 additions and 3 deletions
|
@ -2918,6 +2918,17 @@ impl Editor {
|
|||
.next()
|
||||
.map_or(true, |c| scope.should_autoclose_before(c));
|
||||
|
||||
let preceding_text_allows_autoclose = selection.start.column == 0
|
||||
|| snapshot.reversed_chars_at(selection.start).next().map_or(
|
||||
true,
|
||||
|c| {
|
||||
bracket_pair.start != bracket_pair.end
|
||||
|| !snapshot
|
||||
.char_classifier_at(selection.start)
|
||||
.is_word(c)
|
||||
},
|
||||
);
|
||||
|
||||
let is_closing_quote = if bracket_pair.end == bracket_pair.start
|
||||
&& bracket_pair.start.len() == 1
|
||||
{
|
||||
|
@ -2935,6 +2946,7 @@ impl Editor {
|
|||
if autoclose
|
||||
&& bracket_pair.close
|
||||
&& following_text_allows_autoclose
|
||||
&& preceding_text_allows_autoclose
|
||||
&& !is_closing_quote
|
||||
{
|
||||
let anchor = snapshot.anchor_before(selection.end);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue