Fix RSLang editing

This commit is contained in:
IRBorisov 2023-08-27 19:48:08 +03:00
parent be360312d4
commit 0134af6b57
2 changed files with 21 additions and 19 deletions

View File

@ -21,5 +21,11 @@ const darkTheme = EditorView.baseTheme(bracketsDarkT);
const lightTheme = EditorView.baseTheme(bracketsLightT); const lightTheme = EditorView.baseTheme(bracketsLightT);
export function ccBracketMatching(darkMode: boolean) { export function ccBracketMatching(darkMode: boolean) {
return [bracketMatching({ renderMatch: bracketRender }), darkMode ? darkTheme : lightTheme]; return [
bracketMatching({
renderMatch: bracketRender,
brackets:'{}[]()'
}),
darkMode ? darkTheme : lightTheme
];
} }

View File

@ -51,15 +51,19 @@ export class TextWrapper {
} }
envelopeWith(left: string, right: string) { envelopeWith(left: string, right: string) {
const hasSelection = this.ref.view.state.selection.main.from !== this.ref.view.state.selection.main.to
const newSelection = hasSelection ? {
anchor: this.ref.view.state.selection.main.from,
head: this.ref.view.state.selection.main.to + left.length + right.length
} : {
anchor: this.ref.view.state.selection.main.to + left.length + right.length - 1,
}
this.ref.view.dispatch({ this.ref.view.dispatch({
changes: [ changes: [
{from: this.ref.view.state.selection.main.from, insert: left}, {from: this.ref.view.state.selection.main.from, insert: left},
{from: this.ref.view.state.selection.main.to, insert: right} {from: this.ref.view.state.selection.main.to, insert: right}
], ],
selection: { selection: newSelection
anchor: this.ref.view.state.selection.main.from,
head: this.ref.view.state.selection.main.to + left.length + right.length
}
}); });
} }
@ -89,11 +93,6 @@ export class TextWrapper {
} else { } else {
this.envelopeWith('I{(σ, γ) | σ:∈X1; γ:=F1[σ]; P1[σ, γ]', '}'); this.envelopeWith('I{(σ, γ) | σ:∈X1; γ:=F1[σ]; P1[σ, γ]', '}');
} }
this.ref.view.dispatch({
selection: {
anchor: this.ref.view.state.selection.main.from + 2,
}
});
return true; return true;
} }
case TokenID.NT_RECURSIVE_FULL: { case TokenID.NT_RECURSIVE_FULL: {
@ -102,11 +101,6 @@ export class TextWrapper {
} else { } else {
this.envelopeWith('R{ξ:=D1 | F1[ξ]≠∅ | ξF1[ξ]', '}'); this.envelopeWith('R{ξ:=D1 | F1[ξ]≠∅ | ξF1[ξ]', '}');
} }
this.ref.view.dispatch({
selection: {
anchor: this.ref.view.state.selection.main.from + 2,
}
});
return true; return true;
} }
case TokenID.BIGPR: this.envelopeWith('Pr1(', ')'); return true; case TokenID.BIGPR: this.envelopeWith('Pr1(', ')'); return true;
@ -128,11 +122,13 @@ export class TextWrapper {
} }
case TokenID.PUNC_SL: { case TokenID.PUNC_SL: {
this.envelopeWith('[', ']'); this.envelopeWith('[', ']');
this.ref.view.dispatch({ if (hasSelection) {
selection: { this.ref.view.dispatch({
anchor: hasSelection ? this.ref.view.state.selection.main.to: this.ref.view.state.selection.main.from + 1, selection: {
} anchor: hasSelection ? this.ref.view.state.selection.main.to: this.ref.view.state.selection.main.from + 1,
}
}); });
}
return true; return true;
} }
case TokenID.BOOLEAN: { case TokenID.BOOLEAN: {