Mercurial > obsidian-remember-file-state
annotate src/main.ts @ 15:5a3d7a73c3d2
Added tag 1.0.3 for changeset 67468d40c903
| author | Ludovic Chabant <ludovic@chabant.com> |
|---|---|
| date | Mon, 28 Feb 2022 22:15:29 -0800 |
| parents | 7da0dec2dc8d |
| children | a50ef39473b6 |
| rev | line source |
|---|---|
| 0 | 1 import { |
| 2 Editor, | |
| 3 MarkdownView, | |
| 4 OpenViewState, | |
| 5 Plugin, | |
| 6 View | |
| 7 } from 'obsidian'; | |
| 8 | |
| 9 import { | |
| 2 | 10 EditorState, |
| 0 | 11 EditorSelection |
| 12 } from '@codemirror/state'; | |
| 13 | |
| 14 import { | |
| 15 around | |
| 16 } from 'monkey-around'; | |
| 17 | |
| 18 import { | |
| 19 DEFAULT_SETTINGS, | |
| 20 RememberFileStatePluginSettings, | |
| 21 RememberFileStatePluginSettingTab | |
| 22 } from './settings'; | |
| 23 | |
| 24 // Interface for a file state. | |
| 25 interface RememberedFileState { | |
| 26 path: string; | |
| 27 lastSavedTime: number; | |
| 28 stateData: Object; | |
| 29 } | |
| 30 | |
| 31 // Interface for all currently remembered file states. | |
| 32 interface RememberFileStatePluginData { | |
|
11
6f7f35af6335
Better type information for the plugin data
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
33 rememberedFiles: Record<string, RememberedFileState>; |
| 0 | 34 } |
| 35 | |
| 36 // Default empty list of remembered file states. | |
| 37 const DEFAULT_DATA: RememberFileStatePluginData = { | |
|
8
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
38 rememberedFiles: {} |
| 0 | 39 }; |
| 40 | |
| 41 export default class RememberFileStatePlugin extends Plugin { | |
| 42 settings: RememberFileStatePluginSettings; | |
| 43 data: RememberFileStatePluginData; | |
| 44 | |
|
6
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
45 // Don't restore state on the next file being opened. |
| 0 | 46 private _suppressNextFileOpen: boolean = false; |
|
6
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
47 // Next unique ID to identify views without keeping references to them. |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
48 private _nextUniqueViewId: number = 0; |
| 0 | 49 |
|
6
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
50 // Functions to unregister any monkey-patched view hooks on plugin unload. |
| 0 | 51 private _viewUninstallers = {}; |
|
6
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
52 // Functions to unregister any global callbacks on plugin unload. |
| 0 | 53 private _globalUninstallers = []; |
| 54 | |
| 55 async onload() { | |
| 56 console.log("Loading RememberFileState plugin"); | |
| 57 | |
| 58 await this.loadSettings(); | |
| 59 | |
| 60 this.data = Object.assign({}, DEFAULT_DATA); | |
| 61 | |
| 62 this.registerEvent(this.app.workspace.on('file-open', this.onFileOpen)); | |
| 63 this.registerEvent(this.app.vault.on('rename', this.onFileRename)); | |
| 64 this.registerEvent(this.app.vault.on('delete', this.onFileDelete)); | |
| 65 | |
| 66 this.app.workspace.getLeavesOfType("markdown").forEach( | |
| 67 (leaf) => { this.registerOnUnloadFile(leaf.view); }); | |
| 68 | |
| 69 const _this = this; | |
| 70 var uninstall = around(this.app.workspace, { | |
| 71 openLinkText: function(next) { | |
| 72 return async function( | |
| 73 linktext: string, sourcePath: string, | |
| 74 newLeaf?: boolean, openViewState?: OpenViewState) { | |
| 75 // When opening a link, we don't want to restore the | |
| 76 // scroll position/selection/etc because there's a | |
| 77 // good chance we want to show the file back at the | |
| 78 // top, or we're going straight to a specific block. | |
| 79 _this._suppressNextFileOpen = true; | |
| 80 return await next.call( | |
| 81 this, linktext, sourcePath, newLeaf, openViewState); | |
| 82 }; | |
| 83 } | |
| 84 }); | |
| 85 this._globalUninstallers.push(uninstall); | |
| 86 | |
| 87 this.addSettingTab(new RememberFileStatePluginSettingTab(this.app, this)); | |
| 88 } | |
| 89 | |
| 90 onunload() { | |
|
6
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
91 // Run view uninstallers on all current views. |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
92 var numViews: number = 0; |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
93 this.app.workspace.getLeavesOfType("markdown").forEach( |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
94 (leaf) => { |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
95 const filePath = leaf.view.file.path; |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
96 const viewId = this.getUniqueViewId(leaf.view); |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
97 if (viewId != undefined) { |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
98 var uninstaller = this._viewUninstallers[viewId]; |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
99 if (uninstaller) { |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
100 console.debug(`Uninstalling hooks for view ${viewId}`, filePath); |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
101 uninstaller(leaf.view); |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
102 ++numViews; |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
103 } else { |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
104 console.debug("Found markdown view without an uninstaller!", filePath); |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
105 } |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
106 // Clear the ID so we don't get confused if the plugin |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
107 // is re-enabled later. |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
108 this.clearUniqueViewId(leaf.view); |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
109 } else { |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
110 console.debug("Found markdown view without an ID!", filePath); |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
111 } |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
112 }); |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
113 console.debug(`Unregistered ${numViews} view callbacks`); |
| 0 | 114 this._viewUninstallers = {}; |
| 115 | |
|
6
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
116 // Run global unhooks. |
| 0 | 117 this._globalUninstallers.forEach((cb) => cb()); |
| 118 } | |
| 119 | |
| 120 async loadSettings() { | |
| 121 this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); | |
| 122 } | |
| 123 | |
| 124 async saveSettings() { | |
| 125 await this.saveData(this.settings); | |
| 126 } | |
| 127 | |
| 128 private readonly registerOnUnloadFile = function(view) { | |
|
6
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
129 var filePath = view.file.path; |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
130 var viewId = this.getUniqueViewId(view, true); |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
131 if (viewId in this._viewUninstallers) { |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
132 console.debug(`View ${viewId} is already registered`, filePath); |
| 0 | 133 return; |
| 134 } | |
| 135 | |
|
6
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
136 console.debug(`Registering callback on view ${viewId}`, filePath); |
| 0 | 137 const _this = this; |
| 138 var uninstall = around(view, { | |
| 139 onUnloadFile: function(next) { | |
| 140 return async function (unloaded: TFile) { | |
|
12
42396b88c64d
Don't unnecessarily capture the view reference in injected callbacks
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
141 _this.rememberFileState(unloaded, this); |
| 0 | 142 return await next.call(this, unloaded); |
| 143 }; | |
| 144 } | |
| 145 }); | |
|
6
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
146 this._viewUninstallers[viewId] = uninstall; |
| 0 | 147 |
| 148 view.register(() => { | |
|
6
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
149 // Don't hold a reference to this plugin here because this callback |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
150 // will outlive it if it gets deactivated. So let's find it, and |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
151 // do nothing if we don't find it. |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
152 var plugin = app.plugins.getPlugin("remember-file-state"); |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
153 if (plugin) { |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
154 console.debug(`Unregistering view ${viewId} callback`, filePath); |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
155 delete plugin._viewUninstallers[viewId]; |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
156 uninstall(); |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
157 } else { |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
158 console.debug( |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
159 "Plugin remember-file-state has been unloaded, ignoring unregister"); |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
160 } |
| 0 | 161 }); |
| 162 } | |
| 163 | |
| 164 private readonly onFileOpen = async ( | |
| 165 openedFile: TFile | |
| 166 ): Promise<void> => { | |
| 167 // If `openedFile` is null, it's because the last pane was closed | |
| 168 // and there is now an empty pane. | |
| 169 if (openedFile) { | |
| 2 | 170 var activeView = this.app.workspace.getActiveViewOfType(MarkdownView); |
|
7
b1cb0474bb18
Fix possible crash when an opened file isn't a markdown file
Ludovic Chabant <ludovic@chabant.com>
parents:
6
diff
changeset
|
171 if (activeView) { |
|
b1cb0474bb18
Fix possible crash when an opened file isn't a markdown file
Ludovic Chabant <ludovic@chabant.com>
parents:
6
diff
changeset
|
172 this.registerOnUnloadFile(activeView); |
| 0 | 173 |
|
7
b1cb0474bb18
Fix possible crash when an opened file isn't a markdown file
Ludovic Chabant <ludovic@chabant.com>
parents:
6
diff
changeset
|
174 if (!this._suppressNextFileOpen) { |
|
b1cb0474bb18
Fix possible crash when an opened file isn't a markdown file
Ludovic Chabant <ludovic@chabant.com>
parents:
6
diff
changeset
|
175 this.restoreFileState(openedFile, activeView); |
|
b1cb0474bb18
Fix possible crash when an opened file isn't a markdown file
Ludovic Chabant <ludovic@chabant.com>
parents:
6
diff
changeset
|
176 } |
| 0 | 177 } |
|
7
b1cb0474bb18
Fix possible crash when an opened file isn't a markdown file
Ludovic Chabant <ludovic@chabant.com>
parents:
6
diff
changeset
|
178 // else: the file isn't handled by a markdown editor. |
|
b1cb0474bb18
Fix possible crash when an opened file isn't a markdown file
Ludovic Chabant <ludovic@chabant.com>
parents:
6
diff
changeset
|
179 |
|
b1cb0474bb18
Fix possible crash when an opened file isn't a markdown file
Ludovic Chabant <ludovic@chabant.com>
parents:
6
diff
changeset
|
180 this._suppressNextFileOpen = false; |
| 0 | 181 } |
| 182 } | |
| 183 | |
| 184 private readonly rememberFileState = async (file: TFile, view: View): Promise<void> => { | |
| 185 const scrollInfo = view.editor.getScrollInfo(); | |
|
13
7da0dec2dc8d
Simple bail out when legacy editors are enabled
Ludovic Chabant <ludovic@chabant.com>
parents:
12
diff
changeset
|
186 const stateSelection = view.editor.cm.state.selection; |
|
7da0dec2dc8d
Simple bail out when legacy editors are enabled
Ludovic Chabant <ludovic@chabant.com>
parents:
12
diff
changeset
|
187 if (stateSelection == undefined) { |
|
7da0dec2dc8d
Simple bail out when legacy editors are enabled
Ludovic Chabant <ludovic@chabant.com>
parents:
12
diff
changeset
|
188 // Legacy editor is in use, let's ignore |
|
7da0dec2dc8d
Simple bail out when legacy editors are enabled
Ludovic Chabant <ludovic@chabant.com>
parents:
12
diff
changeset
|
189 return; |
|
7da0dec2dc8d
Simple bail out when legacy editors are enabled
Ludovic Chabant <ludovic@chabant.com>
parents:
12
diff
changeset
|
190 } |
|
7da0dec2dc8d
Simple bail out when legacy editors are enabled
Ludovic Chabant <ludovic@chabant.com>
parents:
12
diff
changeset
|
191 const stateSelectionJSON = stateSelection.toJSON(); |
| 0 | 192 const stateData = {'scrollInfo': scrollInfo, 'selection': stateSelectionJSON}; |
| 193 | |
|
8
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
194 var existingFile = this.data.rememberedFiles[file.path]; |
| 0 | 195 if (existingFile) { |
| 196 existingFile.lastSavedTime = Date.now(); | |
| 197 existingFile.stateData = stateData; | |
| 198 } else { | |
| 199 let newFileState = { | |
| 200 path: file.path, | |
| 201 lastSavedTime: Date.now(), | |
| 202 stateData: stateData | |
| 203 }; | |
|
8
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
204 this.data.rememberedFiles[file.path] = newFileState; |
| 0 | 205 |
| 206 // If we need to keep the number remembered files under a maximum, | |
| 207 // do it now. | |
| 208 this.forgetExcessFiles(); | |
| 209 } | |
| 210 console.debug("Remember file state for:", file.path); | |
| 211 } | |
| 212 | |
|
6
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
213 private readonly restoreFileState = function(file: TFile, view: View) { |
|
8
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
214 const existingFile = this.data.rememberedFiles[file.path]; |
| 0 | 215 if (existingFile) { |
| 216 console.debug("Restoring file state for:", file.path); | |
| 217 const stateData = existingFile.stateData; | |
| 218 view.editor.scrollTo(stateData.scrollInfo.left, stateData.scrollInfo.top); | |
| 2 | 219 var transaction = view.editor.cm.state.update({ |
| 220 selection: EditorSelection.fromJSON(stateData.selection)}) | |
| 221 view.editor.cm.dispatch(transaction); | |
| 0 | 222 } |
| 223 } | |
| 224 | |
|
6
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
225 private readonly forgetExcessFiles = function() { |
| 0 | 226 const keepMax = this.settings.rememberMaxFiles; |
| 227 if (keepMax <= 0) { | |
| 228 return; | |
| 229 } | |
| 230 | |
|
8
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
231 // Sort newer files first, older files last. |
|
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
232 var filesData = Object.values(this.data.rememberedFiles); |
|
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
233 filesData.sort((a, b) => { |
|
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
234 if (a.lastSavedTime > b.lastSavedTime) return -1; // a before b |
|
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
235 if (a.lastSavedTime < b.lastSavedTime) return 1; // b before a |
|
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
236 return 0; |
|
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
237 }); |
| 0 | 238 |
|
8
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
239 // Remove older files past the limit. |
|
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
240 for (var i = keepMax; i < filesData.length; ++i) { |
|
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
241 var fileData = filesData[i]; |
|
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
242 delete this.data.rememberedFiles[fileData.path]; |
| 0 | 243 } |
| 244 } | |
| 245 | |
|
6
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
246 private readonly getUniqueViewId = function(view: View, autocreateId: boolean = false) { |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
247 if (view.__uniqueId == undefined) { |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
248 if (!autocreateId) { |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
249 return -1; |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
250 } |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
251 view.__uniqueId = (this._nextUniqueViewId++); |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
252 return view.__uniqueId; |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
253 } |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
254 return view.__uniqueId; |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
255 } |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
256 |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
257 private readonly clearUniqueViewId = function(view: View) { |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
258 delete view["__uniqueId"]; |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
259 } |
|
114d7e6d2633
Fix various issues around keeping references to editor objects
Ludovic Chabant <ludovic@chabant.com>
parents:
2
diff
changeset
|
260 |
| 0 | 261 private readonly onFileRename = async ( |
| 262 file: TAbstractFile, | |
| 263 oldPath: string, | |
| 264 ): Promise<void> => { | |
|
8
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
265 const existingFile = this.data.rememberedFiles[oldPath]; |
| 0 | 266 if (existingFile) { |
| 267 existingFile.path = file.path; | |
|
8
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
268 delete this.data.rememberedFiles[oldPath]; |
|
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
269 this.data.rememberedFiles[file.path] = existingFile; |
| 0 | 270 } |
| 271 }; | |
| 272 | |
| 273 private readonly onFileDelete = async ( | |
| 274 file: TAbstractFile, | |
| 275 ): Promise<void> => { | |
|
8
ec6c48a07b03
Make the plugin data into a dictionary
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
276 delete this.data.rememberedFiles[file.path]; |
| 0 | 277 }; |
| 278 } | |
| 279 |
