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

2686 delete forward from comment #2690

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changes to Calva.

## [Unreleased]

- Fix: [Del key, after emptying a comment line, then imbalances the next form](https://github.com/BetterThanTomorrow/calva/issues/2686)

## [2.0.482] - 2024-12-03

- Fix: [Added 'replace-refer-all-with-alias' & 'replace-refer-all-with-refer' actions to calva.](https://github.com/BetterThanTomorrow/calva/issues/2667)
Expand Down
60 changes: 57 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import * as inspector from './providers/inspector';

function onDidChangeEditorOrSelection(editor: vscode.TextEditor) {
replHistory.setReplHistoryCommandsActiveContext(editor);
whenContexts.setCursorContextIfChanged(editor);
}

function setKeybindingsEnabledContext() {
Expand Down Expand Up @@ -420,6 +419,54 @@ async function activate(context: vscode.ExtensionContext) {

Object.entries(languageProviders).forEach(registerLangProvider);

// Coordinate event handling that may affect the 'when' cursor contexts.
// Update context upon editor change, selection change, or text change
// (e.g., upon deleting a comment-defining semicolon without moving the point)
// But try not to repeatedly update context in response to the same essential event
// (e.g., most text changes, which also move the point)
// without depending on the order of TextDocumentChangeEvent or TextEditorSelectionChangeEvent
let contextSettingEditor: vscode.TextEditor = undefined;
let contextSettingCircumstances = undefined;
function contextSettingOnChangeActiveTextEditor(editor: vscode.TextEditor) {
whenContexts.setCursorContextIfChanged(editor);
const circumstances = {
version: editor.document.version,
active: editor.selection.active,
};
contextSettingEditor = editor;
contextSettingCircumstances = circumstances;
}
function contextSettingOnTextDocumentChangeEvent(dce: vscode.TextDocumentChangeEvent) {
if (contextSettingEditor) {
const circumstances = {
version: dce.document.version,
active: contextSettingEditor.selection.active,
};
if (
!(
(contextSettingEditor && dce.document !== contextSettingEditor.document) ||
circumstances == contextSettingCircumstances
)
) {
whenContexts.setCursorContextIfChanged(contextSettingEditor);
contextSettingCircumstances = circumstances;
}
}
}
function contextSettingOnChangeTextEditorSelection(tsce: vscode.TextEditorSelectionChangeEvent) {
const circumstances = {
version: tsce.textEditor.document.version,
active: tsce.selections[0].active,
};
if (
!(contextSettingEditor === tsce.textEditor && circumstances == contextSettingCircumstances)
) {
whenContexts.setCursorContextIfChanged(tsce.textEditor);
contextSettingEditor = tsce.textEditor;
contextSettingCircumstances = circumstances;
}
}

//EVENTS
const onDidEvents = {
workspace: {
Expand All @@ -441,7 +488,10 @@ async function activate(context: vscode.ExtensionContext) {
void testRunner.runNamespaceTests(testController, document);
}
},
changeTextDocument: annotations.onDidChangeTextDocument,
changeTextDocument: (e: vscode.TextDocumentChangeEvent) => {
annotations.onDidChangeTextDocument(e);
contextSettingOnTextDocumentChangeEvent(e);
},
closeTextDocument: (document) => {
if (outputWindow.isResultsDoc(document)) {
outputWindow.setContextForReplWindowActive(false);
Expand All @@ -458,8 +508,12 @@ async function activate(context: vscode.ExtensionContext) {
changeActiveTextEditor: (editor) => {
status.update();
onDidChangeEditorOrSelection(editor);
contextSettingOnChangeActiveTextEditor(editor);
},
changeTextEditorSelection: (event) => {
onDidChangeEditorOrSelection(event.textEditor);
contextSettingOnChangeTextEditorSelection(event);
},
changeTextEditorSelection: (event) => onDidChangeEditorOrSelection(event.textEditor),
changeVisibleTextEditors: (editors) => {
if (!editors.some((editor) => outputWindow.isResultsDoc(editor.document))) {
outputWindow.setContextForReplWindowActive(false);
Expand Down