Skip to content

Commit fd9bef8

Browse files
committed
feat: close hunk preview with escape key
close #1027
1 parent 5ea08b8 commit fd9bef8

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/editor/signs/tooltip.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Hunks, type Hunk } from "./hunks";
1010
import { html } from "diff2html";
1111
import { ColorSchemeType } from "diff2html/lib/types";
1212
import { pluginRef } from "src/pluginGlobalRef";
13-
import { editorEditorField, setIcon } from "obsidian";
13+
import { editorEditorField, MarkdownView, setIcon } from "obsidian";
1414

1515
const selectHunkEffectType = StateEffect.define<{
1616
pos: number;
@@ -179,8 +179,23 @@ function createTooltip(
179179
togglePreviewHunk(editor, pos);
180180
};
181181

182+
const scope =
183+
pluginRef.plugin?.app.workspace.getActiveViewOfType(
184+
MarkdownView
185+
)?.scope;
186+
187+
const eventHandler = scope?.register(null, "Escape", (_, __) => {
188+
// close on escape
189+
togglePreviewHunk(editor, pos);
190+
});
191+
182192
return {
183193
dom: contentEl,
194+
destroy: () => {
195+
if (eventHandler) {
196+
scope?.unregister(eventHandler);
197+
}
198+
},
184199
update: (update) => {
185200
pos = update.changes.mapPos(pos);
186201
},

0 commit comments

Comments
 (0)