Skip to content

Commit c3d8ecf

Browse files
committed
*: fix
1 parent e1006d0 commit c3d8ecf

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

lean4-infoview/src/infoview/editorConnection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type EditorEvents = Omit<Eventify<InfoviewApi>, 'requestedAction' | 'clic
2121
* Keys for this event are of the form `` `${action.entry}:${action.id}` ``.
2222
*/
2323
clickedContextMenu: EventEmitter<ContextMenuAction, string>
24+
goToDefinition?: EventEmitter<number, number>
2425
}
2526

2627
/** Provides higher-level wrappers around functionality provided by the editor,

lean4-infoview/src/infoview/main.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ export function renderInfoview(editorApi: EditorApi, uiElement: HTMLElement): In
179179
return infoviewApi
180180
}
181181

182+
declare module '@leanprover/infoview-api' {
183+
interface InfoviewApi {
184+
goToDefinition?: (line: number, character: number) => void;
185+
}
186+
}
187+
188+
189+
182190
export const InfoviewFc: React.FC<
183191
{
184192
mkEditorApi: (infoviewApi: InfoviewApi) => EditorApi;
@@ -204,6 +212,7 @@ export const InfoviewFc: React.FC<
204212
changedInfoviewConfig: new EventEmitter(),
205213
runTestScript: new EventEmitter(),
206214
requestedAction: new EventEmitter(),
215+
clickedContextMenu: new EventEmitter(),
207216
goToDefinition: new EventEmitter(),
208217
}
209218

@@ -223,11 +232,19 @@ export const InfoviewFc: React.FC<
223232
changedCursorLocation: async loc => editorEvents.changedCursorLocation.fire(loc),
224233
changedInfoviewConfig: async conf => editorEvents.changedInfoviewConfig.fire(conf),
225234
requestedAction: async action => editorEvents.requestedAction.fire(action, action.kind),
226-
goToDefinition: async id => editorEvents.goToDefinition.fire(id, id),
235+
goToDefinition: async id => editorEvents?.goToDefinition.fire(id, id),
227236
// See https://rollupjs.org/guide/en/#avoiding-eval
228237
// eslint-disable-next-line @typescript-eslint/no-implied-eval
229238
runTestScript: async script => new Function(script)(),
230239
getInfoviewHtml: async () => document.body.innerHTML,
240+
clickedContextMenu: async action => {
241+
editorEvents.clickedContextMenu.fire(action, `${action.entry}:${action.id}`)
242+
// See comments on `InteractiveCodeTag`.
243+
const sel = window.getSelection()
244+
if (sel && 0 < sel.rangeCount && '_InteractiveCodeTagAutoSelection' in sel.getRangeAt(0))
245+
sel.removeAllRanges()
246+
},
247+
231248
}
232249

233250
const editorApi = mkEditorApi(infoviewApi)
@@ -246,9 +263,9 @@ export const InfoviewFc: React.FC<
246263
return <></>
247264
}
248265

249-
return (
266+
return (
250267
<EditorContext.Provider value={ec}>
251268
<Main />
252269
</EditorContext.Provider>
253-
)
254-
}
270+
)
271+
}

lean4-infoview/src/infoview/userWidget.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,11 @@ import { useRpcSession } from './rpcSessions'
1515
import { DocumentPosition, mapRpcError, useAsyncPersistent } from './util'
1616
import { rewriteModule } from './rewriteModule'
1717

18-
<<<<<<< HEAD
19-
async function dynamicallyLoadModule(hash: string, code: string): Promise<[any, string]> {
20-
const file = new File([code], `widget_${hash}.js`, { type: 'text/javascript' })
21-
const url = URL.createObjectURL(file)
22-
return [await import(url), url]
23-
=======
2418
async function dynamicallyLoadModule(hash: string, code: string): Promise<any> {
2519
const newCode = await rewriteModule(code)
2620
const file = new File([newCode], `widget_${hash}.js`, { type: 'text/javascript' })
2721
const url = URL.createObjectURL(file)
2822
return await import(/* webpackIgnore: true */ url)
29-
>>>>>>> 153f5673 (fix: rewrite dynamic imports)
3023
}
3124

3225
/** Maps module hash to (loaded module, its URI). */

0 commit comments

Comments
 (0)