Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions resources/js/components/CommandPalette.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,20 @@ class Command {
}

export default class CommandPalette {
#preventIfCallbacks = [];

get category() {
return CATEGORY;
}

preventIf(fn) {
this.#preventIfCallbacks.push(fn);
}

shouldPreventOpening() {
return this.#preventIfCallbacks.some(fn => fn());
}

add(command) {
command = new Command(command);

Expand Down
1 change: 1 addition & 0 deletions resources/js/components/command-palette/CommandPalette.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ let recentItems = ref(getRecentItems());
let keyboardBindings = ref([]);

Statamic.$keys.bindGlobal(['mod+k'], (e) => {
if (Statamic.$commandPalette.shouldPreventOpening()) return;
e.preventDefault();
open.value = true;
});
Expand Down
12 changes: 12 additions & 0 deletions resources/js/components/fieldtypes/bard/BardFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ import { data_get } from "@/bootstrap/globals.js";

const lowlight = createLowlight(common);
let tiptap = null;
let commandPaletteCallbackRegistered = false;

export default {
mixins: [Fieldtype, ManagesSetMeta],
Expand Down Expand Up @@ -395,6 +396,17 @@ export default {

this.pageHeader = document.querySelector('.global-header');

if (!commandPaletteCallbackRegistered) {
commandPaletteCallbackRegistered = true;

Statamic.$commandPalette.preventIf(() => {
const selection = window.getSelection();
const node = selection?.anchorNode;
const isInBard = node?.parentElement?.closest('.bard-editor') !== null;
return isInBard && selection?.toString().length > 0;
});
}

this.$nextTick(() => {
let el = document.querySelector(`label[for="${this.fieldId}"]`);
if (el) {
Expand Down
6 changes: 5 additions & 1 deletion resources/js/components/fieldtypes/bard/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ export const Link = Mark.create({

addKeyboardShortcuts() {
return {
'Ctrl-k': () => this.options.vm.events.emit('open-link-toolbar'),
'Ctrl-k': () => {
if (this.editor.state.selection.empty) return false;
this.options.vm.events.emit('open-link-toolbar');
return true;
},
};
},

Expand Down