double-click issue

This commit is contained in:
Gamosoft 2026-06-29 13:07:00 +02:00
parent 581a95b1c8
commit da748caf42
3 changed files with 37 additions and 28 deletions

View File

@ -528,9 +528,7 @@ def generate_export_html(
color: var(--text-secondary, #6a737d); color: var(--text-secondary, #6a737d);
}} }}
/* Callouts / admonitions (GitHub-style: > [!NOTE], > [!TIP], etc.) /* Callouts mirror the in-app preview. */
Mirrors the in-app preview styles so exported/shared notes match.
Hard-coded GitHub palette with rgba backgrounds blends with any theme. */
.markdown-preview .callout {{ .markdown-preview .callout {{
margin: 1rem 0; margin: 1rem 0;
padding: 0.75rem 1rem; padding: 0.75rem 1rem;
@ -797,11 +795,7 @@ def generate_export_html(
// Raw markdown content // Raw markdown content
const markdown = `{escaped_content}`; const markdown = `{escaped_content}`;
// Convert GitHub/Obsidian-style callouts (admonitions) before marked parses. // GitHub-style callouts mirrors the in-app preview preprocessor.
// Mirrors the in-app preview preprocessor so exported/shared notes match.
// Code blocks are protected with placeholders so callout syntax inside
// fenced/inline code is preserved verbatim. Only the 5 GitHub-canonical
// types are recognised; unknown types fall through to plain blockquotes.
let processed; let processed;
{{ {{
const CALLOUT_RE = /^>\\s*\\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\\]\\s*(.*)$/i; const CALLOUT_RE = /^>\\s*\\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\\]\\s*(.*)$/i;

View File

@ -5190,6 +5190,21 @@ function noteApp() {
}, },
// Markdown formatting helpers // Markdown formatting helpers
// Trim trailing whitespace from double-click word selections.
// No-op on browsers that already exclude it (Firefox, Safari).
trimSelectionTrailingSpace(event) {
const editor = event && event.target;
if (!editor) return;
const start = editor.selectionStart;
let end = editor.selectionEnd;
if (start >= end) return;
const text = editor.value;
while (end > start && /\s/.test(text.charAt(end - 1))) end--;
if (end !== editor.selectionEnd) {
editor.setSelectionRange(start, end);
}
},
wrapSelection(before, after, placeholder) { wrapSelection(before, after, placeholder) {
const editor = document.getElementById('note-editor'); const editor = document.getElementById('note-editor');
if (!editor) return; if (!editor) return;
@ -5197,23 +5212,29 @@ function noteApp() {
const start = editor.selectionStart; const start = editor.selectionStart;
const end = editor.selectionEnd; const end = editor.selectionEnd;
const selectedText = this.noteContent.substring(start, end); const selectedText = this.noteContent.substring(start, end);
const textToWrap = selectedText || placeholder;
// Push edge whitespace OUTSIDE inline wrappers — "**house **" is
// invalid per CommonMark. Block wrappers (with \n) keep it intact.
const isInline = !before.includes('\n') && !after.includes('\n');
let leading = '', trailing = '', core = selectedText;
if (isInline && selectedText) {
const m = selectedText.match(/^(\s*)([\s\S]*?)(\s*)$/);
leading = m[1];
core = m[2];
trailing = m[3];
}
const textToWrap = core || placeholder;
// Build the new text // Build the new text
const newText = before + textToWrap + after; const newText = leading + before + textToWrap + after + trailing;
// Update content // Update content
this.noteContent = this.noteContent.substring(0, start) + newText + this.noteContent.substring(end); this.noteContent = this.noteContent.substring(0, start) + newText + this.noteContent.substring(end);
// Set cursor position (select the wrapped text or placeholder)
this.$nextTick(() => { this.$nextTick(() => {
if (selectedText) { const coreStart = start + leading.length + before.length;
// If text was selected, keep it selected (inside the wrapper) const coreEnd = coreStart + textToWrap.length;
editor.setSelectionRange(start + before.length, start + before.length + selectedText.length); editor.setSelectionRange(coreStart, coreEnd);
} else {
// If no text selected, select the placeholder
editor.setSelectionRange(start + before.length, start + before.length + placeholder.length);
}
editor.focus(); editor.focus();
}); });
@ -5811,13 +5832,8 @@ function noteApp() {
} }
); );
// Step 2c: Convert GitHub/Obsidian-style callouts (admonitions). // Step 2c: GitHub-style callouts. Runs inside the code-protection
// Runs while code blocks are still placeholders so callout syntax // window. Unknown types fall through to plain blockquotes.
// inside fenced/inline code is preserved verbatim. The body is
// emitted as a raw HTML block surrounded by blank lines so marked
// still parses inner markdown (bold, links, lists, etc.) per CommonMark.
// Only the 5 GitHub-canonical types are recognised; unknown types
// (e.g. `> [!CUSTOM]`) fall through to plain blockquotes.
{ {
const CALLOUT_RE = /^>\s*\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i; const CALLOUT_RE = /^>\s*\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i;
const CALLOUT_ICONS = { note: '', tip: '💡', important: '❗', warning: '⚠️', caution: '🛑' }; const CALLOUT_ICONS = { note: '', tip: '💡', important: '❗', warning: '⚠️', caution: '🛑' };

View File

@ -545,9 +545,7 @@
color: var(--text-secondary); color: var(--text-secondary);
} }
/* Callouts / admonitions (GitHub-style: > [!NOTE], > [!TIP], etc.) /* Callouts — GitHub-style admonitions (> [!NOTE], etc.) */
Colors are hard-coded GitHub palette with rgba backgrounds so the
tint blends with any theme bg without needing per-theme overrides. */
.markdown-preview .callout { .markdown-preview .callout {
margin: 1rem 0; margin: 1rem 0;
padding: 0.75rem 1rem; padding: 0.75rem 1rem;
@ -3061,6 +3059,7 @@
@scroll="syncOverlayScroll()" @scroll="syncOverlayScroll()"
@keydown.enter="handleEditorEnterKey($event)" @keydown.enter="handleEditorEnterKey($event)"
@keydown.tab="handleTabKey($event)" @keydown.tab="handleTabKey($event)"
@dblclick="trimSelectionTrailingSpace($event)"
@drop="onEditorDrop($event)" @drop="onEditorDrop($event)"
@dragover.prevent="onEditorDragOver($event)" @dragover.prevent="onEditorDragOver($event)"
@dragenter="onEditorDragEnter($event)" @dragenter="onEditorDragEnter($event)"