mirror of
https://github.com/James-Yu/LaTeX-Workshop.git
synced 2024-10-04 23:27:20 +03:00
Fix #3633 Use msg to copy from embeded viewer
This commit is contained in:
parent
0ab151a7d4
commit
be93ab4da5
@ -1,6 +1,7 @@
|
|||||||
import * as vscode from 'vscode'
|
import * as vscode from 'vscode'
|
||||||
import type ws from 'ws'
|
import type ws from 'ws'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
|
import * as os from 'os'
|
||||||
import * as cs from 'cross-spawn'
|
import * as cs from 'cross-spawn'
|
||||||
import * as lw from '../lw'
|
import * as lw from '../lw'
|
||||||
import type { SyncTeXRecordForward } from './locator'
|
import type { SyncTeXRecordForward } from './locator'
|
||||||
@ -280,6 +281,14 @@ export class Viewer {
|
|||||||
logger.log(`${data.message}`)
|
logger.log(`${data.message}`)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
case 'copy': {
|
||||||
|
console.log(data.content)
|
||||||
|
if ((data.isMetaKey && os.platform() === 'darwin') ||
|
||||||
|
(!data.isMetaKey && os.platform() !== 'darwin')) {
|
||||||
|
void vscode.env.clipboard.writeText(data.content as string)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
logger.log(`Unknown websocket message: ${msg}`)
|
logger.log(`Unknown websocket message: ${msg}`)
|
||||||
break
|
break
|
||||||
|
@ -65,6 +65,10 @@ export type ClientRequest = {
|
|||||||
} | {
|
} | {
|
||||||
type: 'add_log',
|
type: 'add_log',
|
||||||
message: string
|
message: string
|
||||||
|
} | {
|
||||||
|
type: 'copy',
|
||||||
|
content: string,
|
||||||
|
isMetaKey: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PanelManagerResponse = {
|
export type PanelManagerResponse = {
|
||||||
|
@ -532,21 +532,27 @@ class LateXWorkshopPdfViewer implements ILatexWorkshopPdfViewer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// keyboard bindings
|
// keyboard bindings
|
||||||
window.addEventListener('keydown', (evt) => {
|
window.addEventListener('keydown', (evt: KeyboardEvent) => {
|
||||||
// F opens find bar, cause Ctrl-F is handled by vscode
|
// F opens find bar, cause Ctrl-F is handled by vscode
|
||||||
const target = evt.target as HTMLElement
|
// const target = evt.target as HTMLElement
|
||||||
if(evt.keyCode === 70 && target.nodeName !== 'INPUT') { // ignore F typed in the search box
|
// if(evt.keyCode === 70 && target.nodeName !== 'INPUT') { // ignore F typed in the search box
|
||||||
this.showToolbar(false)
|
// this.showToolbar(false)
|
||||||
PDFViewerApplication.findBar.open()
|
// PDFViewerApplication.findBar.open()
|
||||||
evt.preventDefault()
|
// evt.preventDefault()
|
||||||
|
// }
|
||||||
|
if (this.embedded && evt.key === 'c' && (evt.ctrlKey || evt.metaKey)) {
|
||||||
|
const selection = window.getSelection()
|
||||||
|
if (selection !== null && selection.toString().length > 0) {
|
||||||
|
this.send({type: 'copy', content: selection.toString(), isMetaKey: evt.metaKey})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chrome's usual Alt-Left/Right (Command-Left/Right on OSX) for history
|
// Chrome's usual Alt-Left/Right (Command-Left/Right on OSX) for history
|
||||||
// Back/Forward don't work in the embedded viewer, so we simulate them.
|
// Back/Forward don't work in the embedded viewer, so we simulate them.
|
||||||
if (this.embedded && (evt.altKey || evt.metaKey)) {
|
if (this.embedded && ((evt.altKey && !navigator.userAgent.includes('Mac OS')) || (evt.metaKey && navigator.userAgent.includes('Mac OS')))) {
|
||||||
if (evt.keyCode === 37) {
|
if (evt.key === 'ArrowLeft') {
|
||||||
this.viewerHistory.back()
|
this.viewerHistory.back()
|
||||||
} else if(evt.keyCode === 39) {
|
} else if(evt.key === 'ArrowRight') {
|
||||||
this.viewerHistory.forward()
|
this.viewerHistory.forward()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user