Implement menu item "Remove"

This commit is contained in:
Jos de Jong 2020-07-27 16:21:09 +02:00
parent 0c418ac846
commit a54e5b6f08
2 changed files with 33 additions and 7 deletions

View File

@ -129,12 +129,13 @@ import { isObjectOrArray } from '../utils/typeUtils.js'
function handleCut() { function handleCut() {
if (selection && selection.paths) { if (selection && selection.paths) {
console.log('cut', { selection, clipboard })
clipboard = selectionToClipboard(selection) clipboard = selectionToClipboard(selection)
const operations = removeAll(selection.paths) const operations = removeAll(selection.paths)
handlePatch(operations) handlePatch(operations)
selection = null
console.log('cut', { selection, clipboard })
} }
} }
@ -156,6 +157,17 @@ import { isObjectOrArray } from '../utils/typeUtils.js'
} }
} }
function handleRemove() {
if (selection && selection.paths) {
console.log('remove', { selection })
const operations = removeAll(selection.paths)
handlePatch(operations)
selection = null
}
}
function handleDuplicate() { function handleDuplicate() {
if (selection && selection.paths) { if (selection && selection.paths) {
console.log('duplicate', { selection }) console.log('duplicate', { selection })
@ -368,7 +380,11 @@ import { isObjectOrArray } from '../utils/typeUtils.js'
event.preventDefault() event.preventDefault()
handleDuplicate() handleDuplicate()
} }
if (combo === 'Ctrl+Insert' || combo === 'Command+Insert') { if (combo === 'Delete') {
event.preventDefault()
handleRemove()
}
if (combo === 'Insert' || combo === 'Insert') {
event.preventDefault() event.preventDefault()
handleInsert('structure') handleInsert('structure')
} }
@ -430,6 +446,7 @@ import { isObjectOrArray } from '../utils/typeUtils.js'
onCut={handleCut} onCut={handleCut}
onCopy={handleCopy} onCopy={handleCopy}
onPaste={handlePaste} onPaste={handlePaste}
onRemove={handleRemove}
onDuplicate={handleDuplicate} onDuplicate={handleDuplicate}
onInsert={handleInsert} onInsert={handleInsert}
onUndo={handleUndo} onUndo={handleUndo}

View File

@ -1,6 +1,6 @@
<script> <script>
import Icon from 'svelte-awesome' import Icon from 'svelte-awesome'
import { faCut, faClone, faCopy, faPaste, faSearch, faUndo, faRedo, faPlus } from '@fortawesome/free-solid-svg-icons' import { faCut, faClone, faCopy, faPaste, faSearch, faUndo, faRedo, faPlus, faTimes } from '@fortawesome/free-solid-svg-icons'
import SearchBox from './SearchBox.svelte' import SearchBox from './SearchBox.svelte'
import DropdownMenu from './DropdownMenu.svelte' import DropdownMenu from './DropdownMenu.svelte'
@ -14,6 +14,7 @@
export let onCut export let onCut
export let onCopy export let onCopy
export let onPaste export let onPaste
export let onRemove
export let onDuplicate export let onDuplicate
export let onInsert export let onInsert
export let onUndo export let onUndo
@ -100,6 +101,15 @@
<div class="separator"></div> <div class="separator"></div>
<button
class="button remove"
on:click={onRemove}
disabled={!hasSelectionContents}
title="remove (Delete)"
>
<Icon data={faTimes} />
</button>
<button <button
class="button duplicate" class="button duplicate"
on:click={onDuplicate} on:click={onDuplicate}
@ -108,10 +118,9 @@
> >
<Icon data={faClone} /> <Icon data={faClone} />
</button> </button>
<DropdownMenu <DropdownMenu
items={insertItems} items={insertItems}
title="Insert new value (Ctrl+Insert)" title="Insert new value (Insert)"
> >
<button <button
class="button insert" class="button insert"