-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enh(ui): smart picker button at the end of line
* Show a `+` button that opens the smart picker. * Show the button when the cursor is at the end of the line. * Do not show the button if the smart picker is already open. * Remove the placeholder text. * Tab navigation to the smart picker works. Signed-off-by: Max <[email protected]>
- Loading branch information
1 parent
b83be2f
commit cbdb933
Showing
4 changed files
with
68 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<!-- | ||
- SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors | ||
- SPDX-License-Identifier: AGPL-3.0-or-later | ||
--> | ||
|
||
<template> | ||
<FloatingMenu :editor="$editor" | ||
:should-show="shouldShow"> | ||
<NcActions :title="t('text', 'Open the Smart Picker')" :type="'tertiary'"> | ||
<NcActionButton @click="openSmartPicker()"> | ||
<template #icon> | ||
<PlusIcon /> | ||
</template> | ||
</NcActionButton> | ||
</NcActions> | ||
</FloatingMenu> | ||
</template> | ||
|
||
<script> | ||
import PlusIcon from 'vue-material-design-icons/Plus.vue' | ||
import { NcActions, NcActionButton } from '@nextcloud/vue' | ||
import { | ||
useEditorMixin, | ||
} from '../Editor.provider.js' | ||
import { FloatingMenu } from '@tiptap/vue-2' | ||
|
||
export default { | ||
name: 'SmartPickerMenu', | ||
components: { | ||
FloatingMenu, | ||
PlusIcon, | ||
NcActions, | ||
NcActionButton, | ||
}, | ||
mixins: [ | ||
useEditorMixin, | ||
], | ||
methods: { | ||
async openSmartPicker() { | ||
const parent = this.$editor.state.selection.$anchor.parent | ||
const content = parent.textContent.match(/(^| )$/) ? '/' : ' /' | ||
this.$editor.chain().focus().insertContent(content).run() | ||
}, | ||
shouldShow({ view, state }) { | ||
const { selection } = state | ||
const { parent, depth, pos } = selection.$anchor | ||
const isRootDepth = depth === 1 | ||
const isEndOfLine = pos === selection.$anchor.end() | ||
const noLinkPickerYet = !parent.textContent.match(/(^| )\/$/) | ||
return view.hasFocus() | ||
&& this.$editor.isEditable | ||
&& isRootDepth | ||
&& isEndOfLine | ||
&& noLinkPickerYet | ||
&& selection.empty | ||
&& parent.isTextblock | ||
&& !parent.type.spec.code | ||
}, | ||
}, | ||
} | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters