🐛 fix(vscode): 代码阅读预览记住浏览位置,编辑 / 预览互切位置对齐
This commit is contained in:
1 parent
6897954644
commit
37306bd23e
13 files changed
+409
-37
No files matched your search
@@ -2,6 +2,7 @@ import type { ExtensionContext, Uri } from 'vscode'
|
||||
import type { CodeReaderApi } from './contract'
|
||||
import { commands, window, workspace } from 'vscode'
|
||||
import { PREVIEW_VIEW_TYPE, PreviewEditorProvider } from './editor/previewEditor'
|
||||
import { showPreview, showSource } from './editor/switchEditor'
|
||||
import { FileTreeProvider } from './explorer/fileTree'
|
||||
import { createPythonAdapter } from './languages/python'
|
||||
import { createTypeScriptAdapter } from './languages/typescript'
|
||||
@@ -14,13 +15,6 @@ import { typescriptZhTranslator } from './translators/typescriptZh'
|
||||
const LANGUAGE_IDS_CONTEXT = 'superpowers.codeReader.languageIds'
|
||||
const FILES_VIEW = 'superpowers.codeReader.files'
|
||||
const OPEN_COMMAND = 'superpowers.codeReader.open'
|
||||
/** VS Code 自带普通文本编辑器的 editor id。 */
|
||||
const TEXT_EDITOR = 'default'
|
||||
/**
|
||||
* VS Code 自带的「重新打开编辑器的方式」:在原标签页位置换成另一种编辑器。
|
||||
* 原文件有未保存改动也不弹保存框——改动在 TextDocument 里,不跟着标签页走。
|
||||
*/
|
||||
const REOPEN_WITH = 'reopenActiveEditorWith'
|
||||
|
||||
/** 按 VS Code 的判断(含 files.associations)取文件的 languageId;图片等二进制文件打不开成文本,返回 undefined。 */
|
||||
async function languageOf(uri: Uri): Promise<string | undefined> {
|
||||
@@ -63,10 +57,8 @@ export function registerCodeReader(context: ExtensionContext): CodeReaderApi {
|
||||
commands.registerCommand('superpowers.codeReader.refresh', () => files.refresh()),
|
||||
commands.registerCommand(OPEN_COMMAND, (uri: Uri) => openFile(uri, registry)),
|
||||
// 标题栏按钮传来的是 (文件 Uri, { groupId }),原样转给 VS Code 定位是哪一组的哪个标签
|
||||
commands.registerCommand('superpowers.codeReader.showPreview', (...args: unknown[]) =>
|
||||
commands.executeCommand(REOPEN_WITH, PREVIEW_VIEW_TYPE, ...args)),
|
||||
commands.registerCommand('superpowers.codeReader.showSource', (...args: unknown[]) =>
|
||||
commands.executeCommand(REOPEN_WITH, TEXT_EDITOR, ...args)),
|
||||
commands.registerCommand('superpowers.codeReader.showPreview', (...args: unknown[]) => showPreview(previews, args)),
|
||||
commands.registerCommand('superpowers.codeReader.showSource', (...args: unknown[]) => showSource(previews, args)),
|
||||
)
|
||||
|
||||
const api: CodeReaderApi = registry
|
||||
|
||||
Reference in new issue
Block a user