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 95a2190
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 7 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'

Check warning on line 8 in src/components/Assistant.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Expected to be enclosed by double quotes
: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 />

Check failure on line 62 in src/components/Editor.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Parsing error: end-tag-with-trailing-solidus
</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
64 changes: 64 additions & 0 deletions src/components/Editor/SmartPickerMenu.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!--
- SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->

<template>
<FloatingMenu :editor="$editor"
:should-show="shouldShow" >

Check failure on line 8 in src/components/Editor/SmartPickerMenu.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Expected no space before '>', but found
<NcActions :title="t('text', 'Open the Smart Picker')" :type="'tertiary'">
<NcActionButton @click="openSmartPicker()" >

Check failure on line 10 in src/components/Editor/SmartPickerMenu.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Expected no space before '>', but found
<template #icon>
<PlusIcon />
</template>
</NcActionButton>
</NcActions>
</FloatingMenu>
</template>

<script>
import PlusIcon from 'vue-material-design-icons/Plus.vue'
import { getLinkWithPicker } from '@nextcloud/vue/dist/Components/NcRichText.js'

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

View workflow job for this annotation

GitHub Actions / NPM lint

'getLinkWithPicker' is defined but never used
import { NcActions, NcActionButton } from '@nextcloud/vue'
import { posToDOMRect } from '@tiptap/core'

Check failure on line 23 in src/components/Editor/SmartPickerMenu.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'posToDOMRect' is defined but never used

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

View check run for this annotation

Codecov / codecov/patch

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

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

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L26 - L27 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 62 in src/components/Editor/SmartPickerMenu.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/SmartPickerMenu.vue#L29-L62

Added lines #L29 - L62 were not covered by tests

</script>
6 changes: 0 additions & 6 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 Down Expand Up @@ -112,11 +111,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 95a2190

Please sign in to comment.