Skip to content

Commit

Permalink
Close #4098 SyncTeX after clicking structure item
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Dec 18, 2023
1 parent 1e1f846 commit 3563af6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 27 deletions.
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,6 @@
"title": "Select the current section",
"category": "LaTeX Workshop"
},
{
"command": "latex-workshop.structure-toggle-follow-cursor",
"title": "Toggle follow cursor",
"category": "LaTeX Workshop"
},
{
"command": "latex-workshop.bibsort",
"title": "Sort BibTeX file",
Expand Down Expand Up @@ -1388,6 +1383,18 @@
],
"markdownDescription": "The names of the commands to be shown in the outline/structure views. The commands must be called in the form `\\commandname{arg}`."
},
"latex-workshop.view.outline.follow.editor": {
"scope": "window",
"type": "boolean",
"default": true,
"markdownDescription": "Whether scrolling the editor will also reveal corresponding structure items."
},
"latex-workshop.view.outline.sync.viewer": {
"scope": "window",
"type": "boolean",
"default": false,
"markdownDescription": "Whether clicking on structure items will also call synctex to scroll the PDF viewer to the corresponding location."
},
"latex-workshop.view.outline.floats.enabled": {
"scope": "window",
"type": "boolean",
Expand Down Expand Up @@ -2504,12 +2511,6 @@
"command": "latex-workshop.build",
"group": "navigation@1"
}
],
"view/title": [
{
"when": "view == latex-workshop-structure",
"command": "latex-workshop.structure-toggle-follow-cursor"
}
]
},
"viewsContainers": {
Expand Down
23 changes: 11 additions & 12 deletions src/core/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,19 @@ export function showLog(compiler?: string) {
}
}

export function gotoSection(filePath: string, lineNumber: number) {
export async function gotoSection(filePath: string, lineNumber: number) {
logger.log(`GOTOSECTION command invoked. Target ${filePath}, line ${lineNumber}`)
const activeEditor = vscode.window.activeTextEditor

void vscode.workspace.openTextDocument(filePath).then((doc) => {
void vscode.window.showTextDocument(doc).then(() => {
// input lineNumber is one-based, while editor position is zero-based.
void vscode.commands.executeCommand('revealLine', {lineNumber, at: 'center'})
if (activeEditor) {
activeEditor.selection = new vscode.Selection(new vscode.Position(lineNumber, 0), new vscode.Position(lineNumber, 0))
}
})
})

const doc = await vscode.workspace.openTextDocument(filePath)
await vscode.window.showTextDocument(doc)
// input lineNumber is one-based, while editor position is zero-based.
await vscode.commands.executeCommand('revealLine', { lineNumber, at: 'center' })
if (vscode.window.activeTextEditor) {
vscode.window.activeTextEditor.selection = new vscode.Selection(new vscode.Position(lineNumber, 0), new vscode.Position(lineNumber, 0))
if (vscode.workspace.getConfiguration('latex-workshop').get('view.outline.sync.viewer') as boolean) {
lw.locate.synctex.toPDF({ line: lineNumber, filePath: doc.fileName })
}
}
}

export function navigateToEnvPair() {
Expand Down
1 change: 0 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ function registerLatexWorkshopCommands(extensionContext: vscode.ExtensionContext
vscode.commands.registerCommand('latex-workshop.compilerlog', () => lw.commands.showLog('compiler')),
vscode.commands.registerCommand('latex-workshop.code-action', (d: vscode.TextDocument, r: vscode.Range, c: number, m: string) => lw.lint.latex.action(d, r, c, m)),
vscode.commands.registerCommand('latex-workshop.goto-section', (filePath: string, lineNumber: number) => lw.commands.gotoSection(filePath, lineNumber)),
vscode.commands.registerCommand('latex-workshop.structure-toggle-follow-cursor', () => { lw.outline.follow = !lw.outline.follow }),
vscode.commands.registerCommand('latex-workshop.navigate-envpair', () => lw.commands.navigateToEnvPair()),
vscode.commands.registerCommand('latex-workshop.select-envcontent', () => lw.commands.selectEnvContent('content')),
vscode.commands.registerCommand('latex-workshop.select-env', () => lw.commands.selectEnvContent('whole')),
Expand Down
5 changes: 2 additions & 3 deletions src/outline/structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const logger = lw.log('Structure')
export const outline = {
reconstruct,
refresh,
reveal,
follow: true
reveal
}

lw.onConfigChange(['view.outline.sections', 'view.outline.commands'], async () => {
Expand Down Expand Up @@ -42,7 +41,7 @@ async function refresh(fireChangedEvent: boolean = true) {
}

function reveal(e: vscode.TextEditorSelectionChangeEvent) {
if (!outline.follow || !state.view.visible) {
if (!(vscode.workspace.getConfiguration('latex-workshop').get('view.outline.follow.editor') as boolean) || !state.view.visible) {
return
}
const line = e.selections[0].active.line
Expand Down

0 comments on commit 3563af6

Please sign in to comment.