11<template >
22 <div class =" mb-2 w-full flex flex-col" >
33 <div class =" flex flex-wrap items-center gap-3 p-1.5 border border-gray-300 dark:border-gray-600 rounded-t-lg bg-gray-50 dark:bg-gray-800 w-full box-border " >
4- <button type =" button" @click =" applyFormat('bold')" :class =" btnClass" title =" Bold" ><IconLetterBoldOutline class =" w-5 h-5" /></button >
5- <button type =" button" @click =" applyFormat('italic')" :class =" btnClass" title =" Italic" ><IconLetterItalicOutline class =" w-5 h-5" /></button >
6- <button type =" button" @click =" applyFormat('underline')" :class =" btnClass" title =" Underline" ><IconLetterUnderlineOutline class =" w-5 h-5" /></button >
7- <button type =" button" @click =" applyFormat('strike')" :class =" btnClass" title =" Strikethrough" ><IconTextSlashOutline class =" w-5 h-5" /></button >
4+ <button type =" button" @click =" applyFormat('bold')" :class =" btnClass" title =" Bold" aria-label = " Bold " ><IconLetterBoldOutline class =" w-5 h-5" /></button >
5+ <button type =" button" @click =" applyFormat('italic')" :class =" btnClass" title =" Italic" aria-label = " Italic " ><IconLetterItalicOutline class =" w-5 h-5" /></button >
6+ <button type =" button" @click =" applyFormat('underline')" :class =" btnClass" title =" Underline" aria-label = " Underline " ><IconLetterUnderlineOutline class =" w-5 h-5" /></button >
7+ <button type =" button" @click =" applyFormat('strike')" :class =" btnClass" title =" Strikethrough" aria-label = " Strikethrough " ><IconTextSlashOutline class =" w-5 h-5" /></button >
88
99 <div class =" w-px h-4 bg-gray-300 dark:bg-gray-600 mx-1" ></div >
1010
11- <button type =" button" @click =" applyFormat('h2')" :class =" btnClass" title =" Heading 2" ><IconH216Solid class =" w-5 h-5" /></button >
12- <button type =" button" @click =" applyFormat('h3')" :class =" btnClass" title =" Heading 3" ><IconH316Solid class =" w-5 h-5" /></button >
13-
11+ <button type =" button" @click =" applyFormat('h2')" :class =" btnClass" title =" Heading 2" aria-label = " Heading 2 " ><IconH216Solid class =" w-5 h-5" /></button >
12+ <button type =" button" @click =" applyFormat('h3')" :class =" btnClass" title =" Heading 3" aria-label = " Heading 3 " ><IconH316Solid class =" w-5 h-5" /></button >
13+
1414 <div class =" w-px h-4 bg-gray-300 dark:bg-gray-600 mx-1" ></div >
1515
16- <button type =" button" @click =" applyFormat('ul')" :class =" btnClass" title =" Bulleted List" ><IconRectangleListOutline class =" w-5 h-5" /></button >
17- <button type =" button" @click =" applyFormat('ol')" :class =" btnClass" title =" Numbered List" ><IconOrderedListOutline class =" w-5 h-5" /></button >
16+ <button type =" button" @click =" applyFormat('ul')" :class =" btnClass" title =" Bulleted List" aria-label = " Bulleted List " ><IconRectangleListOutline class =" w-5 h-5" /></button >
17+ <button type =" button" @click =" applyFormat('ol')" :class =" btnClass" title =" Numbered List" aria-label = " Numbered List " ><IconOrderedListOutline class =" w-5 h-5" /></button >
1818
1919 <div class =" w-px h-4 bg-gray-300 dark:bg-gray-600 mx-1" ></div >
2020
21- <button type =" button" @click =" applyFormat('link')" :class =" btnClass" title =" Link" ><IconLinkOutline class =" w-5 h-5" /></button >
22- <button type =" button" @click =" applyFormat('code')" :class =" btnClass" title =" Code" ><IconCodeOutline class =" w-5 h-5" /></button >
21+ <button type =" button" @click =" applyFormat('link')" :class =" btnClass" title =" Link" aria-label = " Link " ><IconLinkOutline class =" w-5 h-5" /></button >
22+ <button type =" button" @click =" applyFormat('code')" :class =" btnClass" title =" Code" aria-label = " Code " ><IconCodeOutline class =" w-5 h-5" /></button >
2323 </div >
2424
2525 <div
@@ -51,7 +51,7 @@ const props = defineProps<{
5151 meta: any ,
5252}>()
5353
54- const btnClass = " flex items-center justify-center h-8 px-1 rounded hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-200 transition-colors duration-200" ;
54+ const btnClass = ' flex items-center justify-center h-8 px-1 rounded hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-200 transition-colors duration-200' ;
5555
5656const emit = defineEmits ([' update:value' ]);
5757const editorContainer = ref <HTMLElement | null >(null );
@@ -523,8 +523,9 @@ const applyFormat = (type: string) => {
523523 if (! editor || ! model ) return ;
524524 editor .focus ();
525525
526- const selection = editor .getSelection ();
527- if (! selection ) return ;
526+ const rawSelection = editor .getSelection ();
527+ if (! rawSelection ) return ;
528+ const selection = rawSelection .startLineNumber !== rawSelection .endLineNumber && rawSelection .endColumn === 1 ? new monaco .Selection (rawSelection .startLineNumber , rawSelection .startColumn , rawSelection .endLineNumber - 1 , model .getLineMaxColumn (rawSelection .endLineNumber - 1 ),) : rawSelection ;
528529 const selectedText = model .getValueInRange (selection );
529530
530531 const applyEdits = (id : string , edits : monaco .editor .IIdentifiedSingleEditOperation []) => {
@@ -543,11 +544,13 @@ const applyFormat = (type: string) => {
543544
544545 const handleCodeBlock = () => {
545546 const trimmed = selectedText .trim ();
546- if (trimmed .startsWith (' ```' ) && trimmed .endsWith (' ```' )) {
547- const content = trimmed .split (' \n ' ).slice (1 , - 1 ).join (' \n ' );
547+ const match = trimmed .match (/ ^ (`{3,} )[^ \n ] * \n ([\s\S ] * )\n \1 $ / );
548+ if (match ) {
549+ const content = match [2 ];
548550 applyEdits (' unwrap-code' , [{ range: selection , text: content , forceMoveMarkers: true }]);
549551 } else {
550- applyEdits (' wrap-code' , [{ range: selection , text: ` \n\`\`\`\n ${selectedText }\n\`\`\`\n ` , forceMoveMarkers: true }]);
552+ const fence = fenceForCodeBlock (selectedText );
553+ applyEdits (' wrap-code' , [{ range: selection , text: ` \n ${fence }\n ${selectedText }\n ${fence }\n ` , forceMoveMarkers: true }]);
551554 }
552555 };
553556
0 commit comments