@theia/preview 1.45.0 → 1.46.0-next.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -45
- package/lib/browser/index.d.ts +3 -3
- package/lib/browser/index.js +29 -29
- package/lib/browser/markdown/index.d.ts +1 -1
- package/lib/browser/markdown/index.js +28 -28
- package/lib/browser/markdown/markdown-preview-handler.d.ts +28 -28
- package/lib/browser/markdown/markdown-preview-handler.js +301 -301
- package/lib/browser/markdown/markdown-preview-handler.spec.d.ts +1 -1
- package/lib/browser/markdown/markdown-preview-handler.spec.js +193 -193
- package/lib/browser/preview-contribution.d.ts +50 -50
- package/lib/browser/preview-contribution.js +262 -262
- package/lib/browser/preview-frontend-module.d.ts +5 -5
- package/lib/browser/preview-frontend-module.js +52 -52
- package/lib/browser/preview-handler.d.ts +104 -104
- package/lib/browser/preview-handler.js +76 -76
- package/lib/browser/preview-link-normalizer.d.ts +7 -7
- package/lib/browser/preview-link-normalizer.js +54 -54
- package/lib/browser/preview-preferences.d.ts +11 -11
- package/lib/browser/preview-preferences.js +46 -46
- package/lib/browser/preview-uri.d.ts +8 -8
- package/lib/browser/preview-uri.js +47 -47
- package/lib/browser/preview-widget.d.ts +54 -54
- package/lib/browser/preview-widget.js +261 -261
- package/lib/package.spec.js +25 -25
- package/package.json +7 -7
- package/src/browser/index.ts +19 -19
- package/src/browser/markdown/index.ts +17 -17
- package/src/browser/markdown/markdown-preview-handler.spec.ts +228 -228
- package/src/browser/markdown/markdown-preview-handler.ts +309 -309
- package/src/browser/markdown/style/index.css +18 -18
- package/src/browser/markdown/style/markdown.css +203 -203
- package/src/browser/markdown/style/tomorrow.css +105 -105
- package/src/browser/preview-contribution.ts +276 -276
- package/src/browser/preview-frontend-module.ts +57 -57
- package/src/browser/preview-handler.ts +141 -141
- package/src/browser/preview-link-normalizer.ts +40 -40
- package/src/browser/preview-preferences.ts +58 -58
- package/src/browser/preview-uri.ts +43 -43
- package/src/browser/preview-widget.ts +277 -277
- package/src/browser/style/index.css +17 -17
- package/src/browser/style/preview-widget.css +29 -29
- package/src/package.spec.ts +29 -29
|
@@ -1,263 +1,263 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2018 TypeFox and others.
|
|
4
|
-
//
|
|
5
|
-
// This program and the accompanying materials are made available under the
|
|
6
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
//
|
|
9
|
-
// This Source Code may also be made available under the following Secondary
|
|
10
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
// with the GNU Classpath Exception which is available at
|
|
13
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
//
|
|
15
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
-
};
|
|
23
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
24
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
25
|
-
};
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.PreviewContribution = exports.PreviewCommands = void 0;
|
|
28
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
29
|
-
const browser_1 = require("@theia/core/lib/browser");
|
|
30
|
-
const browser_2 = require("@theia/editor/lib/browser");
|
|
31
|
-
const common_1 = require("@theia/core/lib/common");
|
|
32
|
-
const mini_browser_open_handler_1 = require("@theia/mini-browser/lib/browser/mini-browser-open-handler");
|
|
33
|
-
const preview_widget_1 = require("./preview-widget");
|
|
34
|
-
const preview_handler_1 = require("./preview-handler");
|
|
35
|
-
const preview_uri_1 = require("./preview-uri");
|
|
36
|
-
const preview_preferences_1 = require("./preview-preferences");
|
|
37
|
-
const nls_1 = require("@theia/core/lib/common/nls");
|
|
38
|
-
const debounce = require("@theia/core/shared/lodash.debounce");
|
|
39
|
-
var PreviewCommands;
|
|
40
|
-
(function (PreviewCommands) {
|
|
41
|
-
/**
|
|
42
|
-
* No `label`. Otherwise, it would show up in the `Command Palette` and we already have the `Preview` open handler.
|
|
43
|
-
* See in (`WorkspaceCommandContribution`)[https://bit.ly/2DncrSD].
|
|
44
|
-
*/
|
|
45
|
-
PreviewCommands.OPEN = common_1.Command.toLocalizedCommand({
|
|
46
|
-
id: 'preview:open',
|
|
47
|
-
label: 'Open Preview',
|
|
48
|
-
iconClass: (0, browser_1.codicon)('open-preview')
|
|
49
|
-
}, 'vscode.markdown-language-features/package/markdown.preview.title');
|
|
50
|
-
PreviewCommands.OPEN_SOURCE = {
|
|
51
|
-
id: 'preview.open.source',
|
|
52
|
-
iconClass: (0, browser_1.codicon)('go-to-file')
|
|
53
|
-
};
|
|
54
|
-
})(PreviewCommands = exports.PreviewCommands || (exports.PreviewCommands = {}));
|
|
55
|
-
let PreviewContribution =
|
|
56
|
-
// eslint-disable-next-line max-len
|
|
57
|
-
class PreviewContribution extends browser_1.NavigatableWidgetOpenHandler {
|
|
58
|
-
constructor() {
|
|
59
|
-
super(...arguments);
|
|
60
|
-
this.id = preview_uri_1.PreviewUri.id;
|
|
61
|
-
this.label = nls_1.nls.localize(mini_browser_open_handler_1.MiniBrowserCommands.PREVIEW_CATEGORY_KEY, mini_browser_open_handler_1.MiniBrowserCommands.PREVIEW_CATEGORY);
|
|
62
|
-
this.synchronizedUris = new Set();
|
|
63
|
-
this.scrollSyncLockOn = undefined;
|
|
64
|
-
}
|
|
65
|
-
onStart() {
|
|
66
|
-
this.onCreated(previewWidget => {
|
|
67
|
-
this.registerOpenOnDoubleClick(previewWidget);
|
|
68
|
-
this.registerEditorAndPreviewSync(previewWidget);
|
|
69
|
-
});
|
|
70
|
-
this.editorManager.onCreated(editorWidget => {
|
|
71
|
-
this.registerEditorAndPreviewSync(editorWidget);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
async lockScrollSync(on, delay = 50) {
|
|
75
|
-
this.scrollSyncLockOn = on;
|
|
76
|
-
if (this.scrollSyncLockTimeout) {
|
|
77
|
-
window.clearTimeout(this.scrollSyncLockTimeout);
|
|
78
|
-
}
|
|
79
|
-
this.scrollSyncLockTimeout = window.setTimeout(() => {
|
|
80
|
-
this.scrollSyncLockOn = undefined;
|
|
81
|
-
}, delay);
|
|
82
|
-
}
|
|
83
|
-
async registerEditorAndPreviewSync(source) {
|
|
84
|
-
let uri;
|
|
85
|
-
let editorWidget;
|
|
86
|
-
let previewWidget;
|
|
87
|
-
if (source instanceof browser_2.EditorWidget) {
|
|
88
|
-
editorWidget = source;
|
|
89
|
-
uri = editorWidget.editor.uri.toString();
|
|
90
|
-
previewWidget = await this.getWidget(editorWidget.editor.uri);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
previewWidget = source;
|
|
94
|
-
uri = previewWidget.getUri().toString();
|
|
95
|
-
editorWidget = await this.editorManager.getByUri(previewWidget.getUri());
|
|
96
|
-
}
|
|
97
|
-
if (!previewWidget || !editorWidget || !uri) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
if (this.synchronizedUris.has(uri)) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const syncDisposables = new common_1.DisposableCollection();
|
|
104
|
-
previewWidget.disposed.connect(() => syncDisposables.dispose());
|
|
105
|
-
editorWidget.disposed.connect(() => syncDisposables.dispose());
|
|
106
|
-
const editor = editorWidget.editor;
|
|
107
|
-
syncDisposables.push(editor.onScrollChanged(debounce(() => {
|
|
108
|
-
if (this.scrollSyncLockOn === 'editor') {
|
|
109
|
-
// avoid recursive scroll synchronization
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
this.lockScrollSync('preview');
|
|
113
|
-
const range = editor.getVisibleRanges();
|
|
114
|
-
if (range.length > 0) {
|
|
115
|
-
this.revealSourceLineInPreview(previewWidget, range[0].start);
|
|
116
|
-
}
|
|
117
|
-
}), 100));
|
|
118
|
-
syncDisposables.push(this.synchronizeScrollToEditor(previewWidget, editor));
|
|
119
|
-
this.synchronizedUris.add(uri);
|
|
120
|
-
syncDisposables.push(common_1.Disposable.create(() => this.synchronizedUris.delete(uri)));
|
|
121
|
-
}
|
|
122
|
-
revealSourceLineInPreview(previewWidget, position) {
|
|
123
|
-
previewWidget.revealForSourceLine(position.line);
|
|
124
|
-
}
|
|
125
|
-
synchronizeScrollToEditor(previewWidget, editor) {
|
|
126
|
-
return previewWidget.onDidScroll(sourceLine => {
|
|
127
|
-
if (this.scrollSyncLockOn === 'preview') {
|
|
128
|
-
// avoid recursive scroll synchronization
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
const line = Math.floor(sourceLine);
|
|
132
|
-
this.lockScrollSync('editor'); // avoid recursive scroll synchronization
|
|
133
|
-
editor.revealRange({
|
|
134
|
-
start: {
|
|
135
|
-
line,
|
|
136
|
-
character: 0
|
|
137
|
-
},
|
|
138
|
-
end: {
|
|
139
|
-
line: line + 1,
|
|
140
|
-
character: 0
|
|
141
|
-
}
|
|
142
|
-
}, { at: 'top' });
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
registerOpenOnDoubleClick(ref) {
|
|
146
|
-
const disposable = ref.onDidDoubleClick(async (location) => {
|
|
147
|
-
const { editor } = await this.openSource(ref);
|
|
148
|
-
editor.revealPosition(location.range.start);
|
|
149
|
-
editor.selection = location.range;
|
|
150
|
-
ref.revealForSourceLine(location.range.start.line);
|
|
151
|
-
});
|
|
152
|
-
ref.disposed.connect(() => disposable.dispose());
|
|
153
|
-
}
|
|
154
|
-
canHandle(uri) {
|
|
155
|
-
if (!this.previewHandlerProvider.canHandle(uri)) {
|
|
156
|
-
return 0;
|
|
157
|
-
}
|
|
158
|
-
const editorPriority = this.editorManager.canHandle(uri);
|
|
159
|
-
if (editorPriority === 0) {
|
|
160
|
-
return 200;
|
|
161
|
-
}
|
|
162
|
-
if (preview_uri_1.PreviewUri.match(uri)) {
|
|
163
|
-
return editorPriority * 2;
|
|
164
|
-
}
|
|
165
|
-
return editorPriority * (this.openByDefault ? 2 : 0.5);
|
|
166
|
-
}
|
|
167
|
-
get openByDefault() {
|
|
168
|
-
return this.preferences['preview.openByDefault'];
|
|
169
|
-
}
|
|
170
|
-
async open(uri, options) {
|
|
171
|
-
const resolvedOptions = await this.resolveOpenerOptions(options);
|
|
172
|
-
return super.open(uri, resolvedOptions);
|
|
173
|
-
}
|
|
174
|
-
serializeUri(uri) {
|
|
175
|
-
return super.serializeUri(preview_uri_1.PreviewUri.decode(uri));
|
|
176
|
-
}
|
|
177
|
-
async resolveOpenerOptions(options) {
|
|
178
|
-
const resolved = { mode: 'activate', ...options };
|
|
179
|
-
if (resolved.originUri) {
|
|
180
|
-
const ref = await this.getWidget(resolved.originUri);
|
|
181
|
-
if (ref) {
|
|
182
|
-
resolved.widgetOptions = { ...resolved.widgetOptions, ref };
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return resolved;
|
|
186
|
-
}
|
|
187
|
-
registerCommands(registry) {
|
|
188
|
-
registry.registerCommand(PreviewCommands.OPEN, {
|
|
189
|
-
execute: widget => this.openForEditor(widget),
|
|
190
|
-
isEnabled: widget => this.canHandleEditorUri(widget),
|
|
191
|
-
isVisible: widget => this.canHandleEditorUri(widget)
|
|
192
|
-
});
|
|
193
|
-
registry.registerCommand(PreviewCommands.OPEN_SOURCE, {
|
|
194
|
-
execute: widget => this.openSource(widget),
|
|
195
|
-
isEnabled: widget => widget instanceof preview_widget_1.PreviewWidget,
|
|
196
|
-
isVisible: widget => widget instanceof preview_widget_1.PreviewWidget
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
registerMenus(menus) {
|
|
200
|
-
menus.registerMenuAction(browser_2.EditorContextMenu.NAVIGATION, {
|
|
201
|
-
commandId: PreviewCommands.OPEN.id
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
registerToolbarItems(registry) {
|
|
205
|
-
registry.registerItem({
|
|
206
|
-
id: PreviewCommands.OPEN.id,
|
|
207
|
-
command: PreviewCommands.OPEN.id,
|
|
208
|
-
tooltip: nls_1.nls.localize('vscode.markdown-language-features/package/markdown.previewSide.title', 'Open Preview to the Side')
|
|
209
|
-
});
|
|
210
|
-
registry.registerItem({
|
|
211
|
-
id: PreviewCommands.OPEN_SOURCE.id,
|
|
212
|
-
command: PreviewCommands.OPEN_SOURCE.id,
|
|
213
|
-
tooltip: nls_1.nls.localize('vscode.markdown-language-features/package/markdown.showSource.title', 'Open Source')
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
canHandleEditorUri(widget) {
|
|
217
|
-
const uri = this.getCurrentEditorUri(widget);
|
|
218
|
-
return !!uri && this.previewHandlerProvider.canHandle(uri);
|
|
219
|
-
}
|
|
220
|
-
getCurrentEditorUri(widget) {
|
|
221
|
-
const current = this.getCurrentEditor(widget);
|
|
222
|
-
return current && current.editor.uri;
|
|
223
|
-
}
|
|
224
|
-
getCurrentEditor(widget) {
|
|
225
|
-
const current = widget ? widget : this.editorManager.currentEditor;
|
|
226
|
-
return current instanceof browser_2.EditorWidget && current || undefined;
|
|
227
|
-
}
|
|
228
|
-
async openForEditor(widget) {
|
|
229
|
-
const ref = this.getCurrentEditor(widget);
|
|
230
|
-
if (!ref) {
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
await this.open(ref.editor.uri, {
|
|
234
|
-
mode: 'reveal',
|
|
235
|
-
widgetOptions: { ref, mode: 'open-to-right' }
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
async openSource(ref) {
|
|
239
|
-
if (ref instanceof preview_widget_1.PreviewWidget) {
|
|
240
|
-
return this.editorManager.open(ref.uri, {
|
|
241
|
-
widgetOptions: { ref, mode: 'tab-after' }
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
__decorate([
|
|
247
|
-
(0, inversify_1.inject)(browser_2.EditorManager),
|
|
248
|
-
__metadata("design:type", browser_2.EditorManager)
|
|
249
|
-
], PreviewContribution.prototype, "editorManager", void 0);
|
|
250
|
-
__decorate([
|
|
251
|
-
(0, inversify_1.inject)(preview_handler_1.PreviewHandlerProvider),
|
|
252
|
-
__metadata("design:type", preview_handler_1.PreviewHandlerProvider)
|
|
253
|
-
], PreviewContribution.prototype, "previewHandlerProvider", void 0);
|
|
254
|
-
__decorate([
|
|
255
|
-
(0, inversify_1.inject)(preview_preferences_1.PreviewPreferences),
|
|
256
|
-
__metadata("design:type", Object)
|
|
257
|
-
], PreviewContribution.prototype, "preferences", void 0);
|
|
258
|
-
PreviewContribution = __decorate([
|
|
259
|
-
(0, inversify_1.injectable)()
|
|
260
|
-
// eslint-disable-next-line max-len
|
|
261
|
-
], PreviewContribution);
|
|
262
|
-
exports.PreviewContribution = PreviewContribution;
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2018 TypeFox and others.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
+
};
|
|
23
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
24
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.PreviewContribution = exports.PreviewCommands = void 0;
|
|
28
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
29
|
+
const browser_1 = require("@theia/core/lib/browser");
|
|
30
|
+
const browser_2 = require("@theia/editor/lib/browser");
|
|
31
|
+
const common_1 = require("@theia/core/lib/common");
|
|
32
|
+
const mini_browser_open_handler_1 = require("@theia/mini-browser/lib/browser/mini-browser-open-handler");
|
|
33
|
+
const preview_widget_1 = require("./preview-widget");
|
|
34
|
+
const preview_handler_1 = require("./preview-handler");
|
|
35
|
+
const preview_uri_1 = require("./preview-uri");
|
|
36
|
+
const preview_preferences_1 = require("./preview-preferences");
|
|
37
|
+
const nls_1 = require("@theia/core/lib/common/nls");
|
|
38
|
+
const debounce = require("@theia/core/shared/lodash.debounce");
|
|
39
|
+
var PreviewCommands;
|
|
40
|
+
(function (PreviewCommands) {
|
|
41
|
+
/**
|
|
42
|
+
* No `label`. Otherwise, it would show up in the `Command Palette` and we already have the `Preview` open handler.
|
|
43
|
+
* See in (`WorkspaceCommandContribution`)[https://bit.ly/2DncrSD].
|
|
44
|
+
*/
|
|
45
|
+
PreviewCommands.OPEN = common_1.Command.toLocalizedCommand({
|
|
46
|
+
id: 'preview:open',
|
|
47
|
+
label: 'Open Preview',
|
|
48
|
+
iconClass: (0, browser_1.codicon)('open-preview')
|
|
49
|
+
}, 'vscode.markdown-language-features/package/markdown.preview.title');
|
|
50
|
+
PreviewCommands.OPEN_SOURCE = {
|
|
51
|
+
id: 'preview.open.source',
|
|
52
|
+
iconClass: (0, browser_1.codicon)('go-to-file')
|
|
53
|
+
};
|
|
54
|
+
})(PreviewCommands = exports.PreviewCommands || (exports.PreviewCommands = {}));
|
|
55
|
+
let PreviewContribution =
|
|
56
|
+
// eslint-disable-next-line max-len
|
|
57
|
+
class PreviewContribution extends browser_1.NavigatableWidgetOpenHandler {
|
|
58
|
+
constructor() {
|
|
59
|
+
super(...arguments);
|
|
60
|
+
this.id = preview_uri_1.PreviewUri.id;
|
|
61
|
+
this.label = nls_1.nls.localize(mini_browser_open_handler_1.MiniBrowserCommands.PREVIEW_CATEGORY_KEY, mini_browser_open_handler_1.MiniBrowserCommands.PREVIEW_CATEGORY);
|
|
62
|
+
this.synchronizedUris = new Set();
|
|
63
|
+
this.scrollSyncLockOn = undefined;
|
|
64
|
+
}
|
|
65
|
+
onStart() {
|
|
66
|
+
this.onCreated(previewWidget => {
|
|
67
|
+
this.registerOpenOnDoubleClick(previewWidget);
|
|
68
|
+
this.registerEditorAndPreviewSync(previewWidget);
|
|
69
|
+
});
|
|
70
|
+
this.editorManager.onCreated(editorWidget => {
|
|
71
|
+
this.registerEditorAndPreviewSync(editorWidget);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async lockScrollSync(on, delay = 50) {
|
|
75
|
+
this.scrollSyncLockOn = on;
|
|
76
|
+
if (this.scrollSyncLockTimeout) {
|
|
77
|
+
window.clearTimeout(this.scrollSyncLockTimeout);
|
|
78
|
+
}
|
|
79
|
+
this.scrollSyncLockTimeout = window.setTimeout(() => {
|
|
80
|
+
this.scrollSyncLockOn = undefined;
|
|
81
|
+
}, delay);
|
|
82
|
+
}
|
|
83
|
+
async registerEditorAndPreviewSync(source) {
|
|
84
|
+
let uri;
|
|
85
|
+
let editorWidget;
|
|
86
|
+
let previewWidget;
|
|
87
|
+
if (source instanceof browser_2.EditorWidget) {
|
|
88
|
+
editorWidget = source;
|
|
89
|
+
uri = editorWidget.editor.uri.toString();
|
|
90
|
+
previewWidget = await this.getWidget(editorWidget.editor.uri);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
previewWidget = source;
|
|
94
|
+
uri = previewWidget.getUri().toString();
|
|
95
|
+
editorWidget = await this.editorManager.getByUri(previewWidget.getUri());
|
|
96
|
+
}
|
|
97
|
+
if (!previewWidget || !editorWidget || !uri) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (this.synchronizedUris.has(uri)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const syncDisposables = new common_1.DisposableCollection();
|
|
104
|
+
previewWidget.disposed.connect(() => syncDisposables.dispose());
|
|
105
|
+
editorWidget.disposed.connect(() => syncDisposables.dispose());
|
|
106
|
+
const editor = editorWidget.editor;
|
|
107
|
+
syncDisposables.push(editor.onScrollChanged(debounce(() => {
|
|
108
|
+
if (this.scrollSyncLockOn === 'editor') {
|
|
109
|
+
// avoid recursive scroll synchronization
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
this.lockScrollSync('preview');
|
|
113
|
+
const range = editor.getVisibleRanges();
|
|
114
|
+
if (range.length > 0) {
|
|
115
|
+
this.revealSourceLineInPreview(previewWidget, range[0].start);
|
|
116
|
+
}
|
|
117
|
+
}), 100));
|
|
118
|
+
syncDisposables.push(this.synchronizeScrollToEditor(previewWidget, editor));
|
|
119
|
+
this.synchronizedUris.add(uri);
|
|
120
|
+
syncDisposables.push(common_1.Disposable.create(() => this.synchronizedUris.delete(uri)));
|
|
121
|
+
}
|
|
122
|
+
revealSourceLineInPreview(previewWidget, position) {
|
|
123
|
+
previewWidget.revealForSourceLine(position.line);
|
|
124
|
+
}
|
|
125
|
+
synchronizeScrollToEditor(previewWidget, editor) {
|
|
126
|
+
return previewWidget.onDidScroll(sourceLine => {
|
|
127
|
+
if (this.scrollSyncLockOn === 'preview') {
|
|
128
|
+
// avoid recursive scroll synchronization
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const line = Math.floor(sourceLine);
|
|
132
|
+
this.lockScrollSync('editor'); // avoid recursive scroll synchronization
|
|
133
|
+
editor.revealRange({
|
|
134
|
+
start: {
|
|
135
|
+
line,
|
|
136
|
+
character: 0
|
|
137
|
+
},
|
|
138
|
+
end: {
|
|
139
|
+
line: line + 1,
|
|
140
|
+
character: 0
|
|
141
|
+
}
|
|
142
|
+
}, { at: 'top' });
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
registerOpenOnDoubleClick(ref) {
|
|
146
|
+
const disposable = ref.onDidDoubleClick(async (location) => {
|
|
147
|
+
const { editor } = await this.openSource(ref);
|
|
148
|
+
editor.revealPosition(location.range.start);
|
|
149
|
+
editor.selection = location.range;
|
|
150
|
+
ref.revealForSourceLine(location.range.start.line);
|
|
151
|
+
});
|
|
152
|
+
ref.disposed.connect(() => disposable.dispose());
|
|
153
|
+
}
|
|
154
|
+
canHandle(uri) {
|
|
155
|
+
if (!this.previewHandlerProvider.canHandle(uri)) {
|
|
156
|
+
return 0;
|
|
157
|
+
}
|
|
158
|
+
const editorPriority = this.editorManager.canHandle(uri);
|
|
159
|
+
if (editorPriority === 0) {
|
|
160
|
+
return 200;
|
|
161
|
+
}
|
|
162
|
+
if (preview_uri_1.PreviewUri.match(uri)) {
|
|
163
|
+
return editorPriority * 2;
|
|
164
|
+
}
|
|
165
|
+
return editorPriority * (this.openByDefault ? 2 : 0.5);
|
|
166
|
+
}
|
|
167
|
+
get openByDefault() {
|
|
168
|
+
return this.preferences['preview.openByDefault'];
|
|
169
|
+
}
|
|
170
|
+
async open(uri, options) {
|
|
171
|
+
const resolvedOptions = await this.resolveOpenerOptions(options);
|
|
172
|
+
return super.open(uri, resolvedOptions);
|
|
173
|
+
}
|
|
174
|
+
serializeUri(uri) {
|
|
175
|
+
return super.serializeUri(preview_uri_1.PreviewUri.decode(uri));
|
|
176
|
+
}
|
|
177
|
+
async resolveOpenerOptions(options) {
|
|
178
|
+
const resolved = { mode: 'activate', ...options };
|
|
179
|
+
if (resolved.originUri) {
|
|
180
|
+
const ref = await this.getWidget(resolved.originUri);
|
|
181
|
+
if (ref) {
|
|
182
|
+
resolved.widgetOptions = { ...resolved.widgetOptions, ref };
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return resolved;
|
|
186
|
+
}
|
|
187
|
+
registerCommands(registry) {
|
|
188
|
+
registry.registerCommand(PreviewCommands.OPEN, {
|
|
189
|
+
execute: widget => this.openForEditor(widget),
|
|
190
|
+
isEnabled: widget => this.canHandleEditorUri(widget),
|
|
191
|
+
isVisible: widget => this.canHandleEditorUri(widget)
|
|
192
|
+
});
|
|
193
|
+
registry.registerCommand(PreviewCommands.OPEN_SOURCE, {
|
|
194
|
+
execute: widget => this.openSource(widget),
|
|
195
|
+
isEnabled: widget => widget instanceof preview_widget_1.PreviewWidget,
|
|
196
|
+
isVisible: widget => widget instanceof preview_widget_1.PreviewWidget
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
registerMenus(menus) {
|
|
200
|
+
menus.registerMenuAction(browser_2.EditorContextMenu.NAVIGATION, {
|
|
201
|
+
commandId: PreviewCommands.OPEN.id
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
registerToolbarItems(registry) {
|
|
205
|
+
registry.registerItem({
|
|
206
|
+
id: PreviewCommands.OPEN.id,
|
|
207
|
+
command: PreviewCommands.OPEN.id,
|
|
208
|
+
tooltip: nls_1.nls.localize('vscode.markdown-language-features/package/markdown.previewSide.title', 'Open Preview to the Side')
|
|
209
|
+
});
|
|
210
|
+
registry.registerItem({
|
|
211
|
+
id: PreviewCommands.OPEN_SOURCE.id,
|
|
212
|
+
command: PreviewCommands.OPEN_SOURCE.id,
|
|
213
|
+
tooltip: nls_1.nls.localize('vscode.markdown-language-features/package/markdown.showSource.title', 'Open Source')
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
canHandleEditorUri(widget) {
|
|
217
|
+
const uri = this.getCurrentEditorUri(widget);
|
|
218
|
+
return !!uri && this.previewHandlerProvider.canHandle(uri);
|
|
219
|
+
}
|
|
220
|
+
getCurrentEditorUri(widget) {
|
|
221
|
+
const current = this.getCurrentEditor(widget);
|
|
222
|
+
return current && current.editor.uri;
|
|
223
|
+
}
|
|
224
|
+
getCurrentEditor(widget) {
|
|
225
|
+
const current = widget ? widget : this.editorManager.currentEditor;
|
|
226
|
+
return current instanceof browser_2.EditorWidget && current || undefined;
|
|
227
|
+
}
|
|
228
|
+
async openForEditor(widget) {
|
|
229
|
+
const ref = this.getCurrentEditor(widget);
|
|
230
|
+
if (!ref) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
await this.open(ref.editor.uri, {
|
|
234
|
+
mode: 'reveal',
|
|
235
|
+
widgetOptions: { ref, mode: 'open-to-right' }
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
async openSource(ref) {
|
|
239
|
+
if (ref instanceof preview_widget_1.PreviewWidget) {
|
|
240
|
+
return this.editorManager.open(ref.uri, {
|
|
241
|
+
widgetOptions: { ref, mode: 'tab-after' }
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
__decorate([
|
|
247
|
+
(0, inversify_1.inject)(browser_2.EditorManager),
|
|
248
|
+
__metadata("design:type", browser_2.EditorManager)
|
|
249
|
+
], PreviewContribution.prototype, "editorManager", void 0);
|
|
250
|
+
__decorate([
|
|
251
|
+
(0, inversify_1.inject)(preview_handler_1.PreviewHandlerProvider),
|
|
252
|
+
__metadata("design:type", preview_handler_1.PreviewHandlerProvider)
|
|
253
|
+
], PreviewContribution.prototype, "previewHandlerProvider", void 0);
|
|
254
|
+
__decorate([
|
|
255
|
+
(0, inversify_1.inject)(preview_preferences_1.PreviewPreferences),
|
|
256
|
+
__metadata("design:type", Object)
|
|
257
|
+
], PreviewContribution.prototype, "preferences", void 0);
|
|
258
|
+
PreviewContribution = __decorate([
|
|
259
|
+
(0, inversify_1.injectable)()
|
|
260
|
+
// eslint-disable-next-line max-len
|
|
261
|
+
], PreviewContribution);
|
|
262
|
+
exports.PreviewContribution = PreviewContribution;
|
|
263
263
|
//# sourceMappingURL=preview-contribution.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
2
|
-
import '../../src/browser/style/index.css';
|
|
3
|
-
import '../../src/browser/markdown/style/index.css';
|
|
4
|
-
declare const _default: ContainerModule;
|
|
5
|
-
export default _default;
|
|
1
|
+
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
2
|
+
import '../../src/browser/style/index.css';
|
|
3
|
+
import '../../src/browser/markdown/style/index.css';
|
|
4
|
+
declare const _default: ContainerModule;
|
|
5
|
+
export default _default;
|
|
6
6
|
//# sourceMappingURL=preview-frontend-module.d.ts.map
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2018 TypeFox and others.
|
|
4
|
-
//
|
|
5
|
-
// This program and the accompanying materials are made available under the
|
|
6
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
//
|
|
9
|
-
// This Source Code may also be made available under the following Secondary
|
|
10
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
// with the GNU Classpath Exception which is available at
|
|
13
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
//
|
|
15
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
19
|
-
const uri_1 = require("@theia/core/lib/common/uri");
|
|
20
|
-
const common_1 = require("@theia/core/lib/common");
|
|
21
|
-
const browser_1 = require("@theia/core/lib/browser");
|
|
22
|
-
const tab_bar_toolbar_1 = require("@theia/core/lib/browser/shell/tab-bar-toolbar");
|
|
23
|
-
const preview_contribution_1 = require("./preview-contribution");
|
|
24
|
-
const preview_widget_1 = require("./preview-widget");
|
|
25
|
-
const preview_handler_1 = require("./preview-handler");
|
|
26
|
-
const preview_uri_1 = require("./preview-uri");
|
|
27
|
-
const markdown_1 = require("./markdown");
|
|
28
|
-
const preview_preferences_1 = require("./preview-preferences");
|
|
29
|
-
const preview_link_normalizer_1 = require("./preview-link-normalizer");
|
|
30
|
-
require("../../src/browser/style/index.css");
|
|
31
|
-
require("../../src/browser/markdown/style/index.css");
|
|
32
|
-
exports.default = new inversify_1.ContainerModule(bind => {
|
|
33
|
-
(0, preview_preferences_1.bindPreviewPreferences)(bind);
|
|
34
|
-
bind(preview_handler_1.PreviewHandlerProvider).toSelf().inSingletonScope();
|
|
35
|
-
(0, common_1.bindContributionProvider)(bind, preview_handler_1.PreviewHandler);
|
|
36
|
-
bind(markdown_1.MarkdownPreviewHandler).toSelf().inSingletonScope();
|
|
37
|
-
bind(preview_handler_1.PreviewHandler).toService(markdown_1.MarkdownPreviewHandler);
|
|
38
|
-
bind(preview_link_normalizer_1.PreviewLinkNormalizer).toSelf().inSingletonScope();
|
|
39
|
-
bind(preview_widget_1.PreviewWidget).toSelf();
|
|
40
|
-
bind(browser_1.WidgetFactory).toDynamicValue(ctx => ({
|
|
41
|
-
id: preview_uri_1.PreviewUri.id,
|
|
42
|
-
async createWidget(options) {
|
|
43
|
-
const { container } = ctx;
|
|
44
|
-
const resource = await container.get(common_1.ResourceProvider)(new uri_1.default(options.uri));
|
|
45
|
-
const child = container.createChild();
|
|
46
|
-
child.bind(preview_widget_1.PreviewWidgetOptions).toConstantValue({ resource });
|
|
47
|
-
return child.get(preview_widget_1.PreviewWidget);
|
|
48
|
-
}
|
|
49
|
-
})).inSingletonScope();
|
|
50
|
-
bind(preview_contribution_1.PreviewContribution).toSelf().inSingletonScope();
|
|
51
|
-
[common_1.CommandContribution, common_1.MenuContribution, browser_1.OpenHandler, browser_1.FrontendApplicationContribution, tab_bar_toolbar_1.TabBarToolbarContribution].forEach(serviceIdentifier => bind(serviceIdentifier).toService(preview_contribution_1.PreviewContribution));
|
|
52
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2018 TypeFox and others.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
19
|
+
const uri_1 = require("@theia/core/lib/common/uri");
|
|
20
|
+
const common_1 = require("@theia/core/lib/common");
|
|
21
|
+
const browser_1 = require("@theia/core/lib/browser");
|
|
22
|
+
const tab_bar_toolbar_1 = require("@theia/core/lib/browser/shell/tab-bar-toolbar");
|
|
23
|
+
const preview_contribution_1 = require("./preview-contribution");
|
|
24
|
+
const preview_widget_1 = require("./preview-widget");
|
|
25
|
+
const preview_handler_1 = require("./preview-handler");
|
|
26
|
+
const preview_uri_1 = require("./preview-uri");
|
|
27
|
+
const markdown_1 = require("./markdown");
|
|
28
|
+
const preview_preferences_1 = require("./preview-preferences");
|
|
29
|
+
const preview_link_normalizer_1 = require("./preview-link-normalizer");
|
|
30
|
+
require("../../src/browser/style/index.css");
|
|
31
|
+
require("../../src/browser/markdown/style/index.css");
|
|
32
|
+
exports.default = new inversify_1.ContainerModule(bind => {
|
|
33
|
+
(0, preview_preferences_1.bindPreviewPreferences)(bind);
|
|
34
|
+
bind(preview_handler_1.PreviewHandlerProvider).toSelf().inSingletonScope();
|
|
35
|
+
(0, common_1.bindContributionProvider)(bind, preview_handler_1.PreviewHandler);
|
|
36
|
+
bind(markdown_1.MarkdownPreviewHandler).toSelf().inSingletonScope();
|
|
37
|
+
bind(preview_handler_1.PreviewHandler).toService(markdown_1.MarkdownPreviewHandler);
|
|
38
|
+
bind(preview_link_normalizer_1.PreviewLinkNormalizer).toSelf().inSingletonScope();
|
|
39
|
+
bind(preview_widget_1.PreviewWidget).toSelf();
|
|
40
|
+
bind(browser_1.WidgetFactory).toDynamicValue(ctx => ({
|
|
41
|
+
id: preview_uri_1.PreviewUri.id,
|
|
42
|
+
async createWidget(options) {
|
|
43
|
+
const { container } = ctx;
|
|
44
|
+
const resource = await container.get(common_1.ResourceProvider)(new uri_1.default(options.uri));
|
|
45
|
+
const child = container.createChild();
|
|
46
|
+
child.bind(preview_widget_1.PreviewWidgetOptions).toConstantValue({ resource });
|
|
47
|
+
return child.get(preview_widget_1.PreviewWidget);
|
|
48
|
+
}
|
|
49
|
+
})).inSingletonScope();
|
|
50
|
+
bind(preview_contribution_1.PreviewContribution).toSelf().inSingletonScope();
|
|
51
|
+
[common_1.CommandContribution, common_1.MenuContribution, browser_1.OpenHandler, browser_1.FrontendApplicationContribution, tab_bar_toolbar_1.TabBarToolbarContribution].forEach(serviceIdentifier => bind(serviceIdentifier).toService(preview_contribution_1.PreviewContribution));
|
|
52
|
+
});
|
|
53
53
|
//# sourceMappingURL=preview-frontend-module.js.map
|