mirror of
https://github.com/marktext/marktext.git
synced 2025-05-03 00:01:19 +08:00

* Fix tests and improve CI * Add xvfb to Linux - still problems with Mocha e2e tests * Disable Webpack Bundle Analyzer for testing * Use preinstalled yarn application on AppVeyor * Fix build failure with latest vue version * Remove "markdown-toc" * Fix application title unit test * Hide electron window during unit tests * Add basic muya unit tests * Dirty markdown-toc replacement * Update dependencies * Update eslint packages and configuration
48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
import { remote } from 'electron'
|
|
import {
|
|
CUT,
|
|
COPY,
|
|
PASTE,
|
|
COPY_TABLE,
|
|
COPY_AS_MARKDOWN,
|
|
COPY_AS_HTML,
|
|
PASTE_AS_PLAIN_TEXT,
|
|
SEPARATOR,
|
|
INSERT_BEFORE,
|
|
INSERT_AFTER,
|
|
INSERT_ROW,
|
|
REMOVE_ROW,
|
|
INSERT_COLUMN,
|
|
REMOVE_COLUMN
|
|
} from './menuItems'
|
|
|
|
const { Menu, MenuItem } = remote
|
|
|
|
export const showContextMenu = (event, { start, end }) => {
|
|
const menu = new Menu()
|
|
const win = remote.getCurrentWindow()
|
|
const disableCutAndCopy = start.key === end.key && start.offset === end.offset
|
|
const CONTEXT_ITEMS = [INSERT_BEFORE, INSERT_AFTER, SEPARATOR, CUT, COPY, PASTE, SEPARATOR, COPY_AS_MARKDOWN, COPY_AS_HTML, PASTE_AS_PLAIN_TEXT]
|
|
|
|
if (/th|td/.test(start.block.type) && start.key === end.key) {
|
|
CONTEXT_ITEMS.unshift(
|
|
INSERT_ROW,
|
|
REMOVE_ROW,
|
|
INSERT_COLUMN,
|
|
REMOVE_COLUMN,
|
|
SEPARATOR,
|
|
COPY_TABLE,
|
|
SEPARATOR
|
|
)
|
|
}
|
|
|
|
[CUT, COPY, COPY_AS_HTML, COPY_AS_MARKDOWN].forEach(item => {
|
|
item.enabled = !disableCutAndCopy
|
|
})
|
|
|
|
CONTEXT_ITEMS.forEach(item => {
|
|
menu.append(new MenuItem(item))
|
|
})
|
|
menu.popup({ window: win, x: event.clientX, y: event.clientY })
|
|
}
|