Improve context menu

This commit is contained in:
Peter Stuifzand 2020-06-28 23:07:42 +02:00
parent 0ab065bf72
commit 1a06f0cb43
2 changed files with 47 additions and 15 deletions

View File

@ -9,7 +9,6 @@ import search from './search';
import createPageSearch from './fuse';
import util from './util';
import Mustache from 'mustache';
import 'jquery-contextmenu';
import getCaretCoordinates from './caret-position'
import moment from 'moment'
import mermaid from 'mermaid'
@ -22,7 +21,7 @@ import 'prismjs/components/prism-perl'
import 'prismjs/components/prism-css'
import 'prismjs/components/prism-markup-templating'
import 'prismjs/components/prism-jq'
import menu from './menu.js'
import './styles.scss'
moment.locale('nl')
@ -450,19 +449,8 @@ if (holder) {
renderGraphs();
})
})
$.contextMenu({
selector: '.marker',
items: {
copy: {
name: 'Copy',
callback: function (key, opt) {
editor.copy(this).then(result => {
console.log(result)
})
}
}
}
});
menu.connectContextMenu(editor)
}
let timeout = null;

44
editor/src/menu.js Normal file
View File

@ -0,0 +1,44 @@
import $ from 'jquery'
import 'jquery-contextmenu'
function buildContextMenu(editor, store) {
return function (triggeringElement, event) {
return {
items: {
createNewPage: {
name: 'Create page from item',
callback: function (key, opt) {
console.log('Create page from item', key, opt)
}
},
copy: {
name: 'Copy',
callback: function (key, opt) {
editor.copy(this, {recursive: true}).then(result => {
console.log(result)
})
}
},
copyLine: {
name: 'Copy line',
callback: function (key, opt) {
editor.copy(this, {recursive: false}).then(result => {
console.log(result)
})
}
}
}
}
}
}
function connectContextMenu(editor) {
$.contextMenu({
selector: '.marker',
build: buildContextMenu(editor),
});
}
export default {
connectContextMenu: connectContextMenu
}