Skip to content

Commit

Permalink
Provide web client with better enclosing char matching
Browse files Browse the repository at this point in the history
  • Loading branch information
cowuake committed Aug 19, 2024
1 parent 1f5e272 commit d7488b2
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions schemius-web/schemius.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,18 @@ class Schemius {
return false;
}

static matchChar(opening) {
const closing = Schemius.matchingChars[opening];
Schemius.terminal.cmd().insert(opening);
Schemius.terminal.cmd().insert(closing);
Schemius.dispatchKeyEvent("ArrowLeft");
static matchEnclosingChar(openingChar) {
const closingChar = Schemius.matchingChars[openingChar];
const position = Schemius.terminal.get_position();
const picker = Schemius.terminal.cmd().get();
const followingChar = picker[position];

Schemius.terminal.cmd().insert(openingChar);

if (!followingChar || followingChar !== openingChar) {
Schemius.terminal.cmd().insert(closingChar);
Schemius.dispatchKeyEvent("ArrowLeft");
}
}

static handleDelete() {
Expand Down Expand Up @@ -317,7 +324,7 @@ class Schemius {
}
}
} else if (!Schemius.isMobile() && e.key in Schemius.matchingChars) {
Schemius.matchChar(e.key);
Schemius.matchEnclosingChar(e.key);
return false;
} else if (!Schemius.isMobile() && e.key === "BACKSPACE") {
Schemius.handleDelete();
Expand Down

0 comments on commit d7488b2

Please sign in to comment.