File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import { Hunks, type Hunk } from "./hunks";
1010import { html } from "diff2html" ;
1111import { ColorSchemeType } from "diff2html/lib/types" ;
1212import { pluginRef } from "src/pluginGlobalRef" ;
13- import { editorEditorField , setIcon } from "obsidian" ;
13+ import { editorEditorField , MarkdownView , setIcon } from "obsidian" ;
1414
1515const 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 } ,
You can’t perform that action at this time.
0 commit comments