Skip to content

Commit

Permalink
enh(ui): smart picker button at the end of line
Browse files Browse the repository at this point in the history
* 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
max-nextcloud committed Jan 15, 2025
1 parent b83be2f commit cbdb933
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/components/Assistant.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<template>
<div v-if="showAssistant" class="text-assistant">
<FloatingMenu v-if="$editor"
plugin-key="assistantMenu"
:editor="$editor"
:tippy-options="floatingOptions()"
:should-show="floatingShow"
Expand Down
6 changes: 5 additions & 1 deletion src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@
<div v-else class="menubar-placeholder" />
</template>
<ContentContainer v-show="contentLoaded"
ref="contentWrapper" />
ref="contentWrapper">
<SmartPickerMenu />
</ContentContainer>
</MainContainer>
<Reader v-if="isResolvingConflict"
:content="syncError.data.outsideChange"
Expand Down Expand Up @@ -123,6 +125,7 @@ import MainContainer from './Editor/MainContainer.vue'
import Wrapper from './Editor/Wrapper.vue'
import SkeletonLoading from './SkeletonLoading.vue'
import Assistant from './Assistant.vue'
import SmartPickerMenu from './Editor/SmartPickerMenu.vue'

Check warning on line 128 in src/components/Editor.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor.vue#L128

Added line #L128 was not covered by tests
import Translate from './Modal/Translate.vue'
import { generateRemoteUrl } from '@nextcloud/router'
import { fetchNode } from '../services/WebdavClient.ts'
Expand All @@ -141,6 +144,7 @@ export default {
Status,
Assistant,
Translate,
SmartPickerMenu,

Check warning on line 147 in src/components/Editor.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor.vue#L147

Added line #L147 was not covered by tests
},
mixins: [
isMobile,
Expand Down
62 changes: 62 additions & 0 deletions src/components/Editor/SmartPickerMenu.vue
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'

Check warning on line 21 in src/components/Editor/SmartPickerMenu.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/SmartPickerMenu.vue#L20-L21

Added lines #L20 - L21 were not covered by tests
import {
useEditorMixin,
} from '../Editor.provider.js'
import { FloatingMenu } from '@tiptap/vue-2'

Check warning on line 25 in src/components/Editor/SmartPickerMenu.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/SmartPickerMenu.vue#L24-L25

Added lines #L24 - L25 were not covered by tests

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
},
},
}

Check warning on line 60 in src/components/Editor/SmartPickerMenu.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/SmartPickerMenu.vue#L27-L60

Added lines #L27 - L60 were not covered by tests

</script>
7 changes: 0 additions & 7 deletions src/extensions/RichText.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import Mention from './../extensions/Mention.js'
import Search from './../extensions/Search.js'
import OrderedList from './../nodes/OrderedList.js'
import Paragraph from './../nodes/Paragraph.js'
import Placeholder from '@tiptap/extension-placeholder'
import Preview from './../nodes/Preview.js'
import Table from './../nodes/Table.js'
import TaskItem from './../nodes/TaskItem.js'
Expand All @@ -45,7 +44,6 @@ import TrailingNode from './../nodes/TrailingNode.js'
/* eslint-enable import/no-named-as-default */

import { Strong, Italic, Strike, Link, Underline } from './../marks/index.js'
import { translate as t } from '@nextcloud/l10n'

const lowlight = createLowlight(common)
lowlight.registerAlias('plaintext', 'mermaid')
Expand Down Expand Up @@ -112,11 +110,6 @@ export default Extension.create({
relativePath: this.options.relativePath,
}),
LinkBubble,
this.options.editing
? Placeholder.configure({
placeholder: t('text', 'Start writing, or try \'/\' to add, \'@\' to mention…'),
})
: null,
TrailingNode,
]
const additionalExtensionNames = this.options.extensions.map(e => e.name)
Expand Down

0 comments on commit cbdb933

Please sign in to comment.