Skip to content

Commit

Permalink
Fix #920 - Multi-byte date triggers break when date is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmeyers committed Apr 18, 2024
1 parent 7829317 commit d394e85
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/Editor/datepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { Instance } from './flatpickr/types/instance';

export function applyDate(ctx: EditorSuggestContext, stateManager: StateManager, date: Date) {
const dateFormat = stateManager.getSetting('date-format');
const dateTrigger = stateManager.getSetting('date-trigger');
const shouldLinkDates = stateManager.getSetting('link-date-to-daily-note');

const formattedDate = moment(date).format(dateFormat);
const wrappedDate = shouldLinkDates
? buildLinkToDailyNote(stateManager.app, formattedDate)
: `{${formattedDate}} `;

const start = { line: ctx.start.line, ch: ctx.start.ch + 1 };
const start = { line: ctx.start.line, ch: ctx.start.ch + dateTrigger.length };

ctx.editor.replaceRange(wrappedDate, start, ctx.end);
ctx.editor.setCursor({
Expand Down

0 comments on commit d394e85

Please sign in to comment.