Skip to content

Commit

Permalink
Merge pull request #2690 from pbwolf/wip/2686-deleteForward-from-comment
Browse files Browse the repository at this point in the history
2686 delete forward from comment
  • Loading branch information
bpringe authored Jan 6, 2025
2 parents 0441669 + aa0713f commit b8bcccd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
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

0 comments on commit b8bcccd

Please sign in to comment.