fix preview and select of img alt
This commit is contained in:
@@ -224,7 +224,7 @@ export class UmbInputMarkdownElement extends FormControlMixin(UmbLitElement) {
|
|||||||
const selection = this.#editor?.getSelections()[0];
|
const selection = this.#editor?.getSelections()[0];
|
||||||
if (!selection) return;
|
if (!selection) return;
|
||||||
|
|
||||||
const alt = this.#editor?.getValueInRange(selection);
|
const alt = this.#editor?.getValueInRange(selection) || 'alt text';
|
||||||
|
|
||||||
this._focusEditor(); // Focus before opening modal, otherwise cannot regain focus back after modal
|
this._focusEditor(); // Focus before opening modal, otherwise cannot regain focus back after modal
|
||||||
const modalContext = this._modalContext?.open(UMB_MEDIA_TREE_PICKER_MODAL, {});
|
const modalContext = this._modalContext?.open(UMB_MEDIA_TREE_PICKER_MODAL, {});
|
||||||
@@ -234,21 +234,18 @@ export class UmbInputMarkdownElement extends FormControlMixin(UmbLitElement) {
|
|||||||
.then((data) => {
|
.then((data) => {
|
||||||
const imgUrl = data.selection[0];
|
const imgUrl = data.selection[0];
|
||||||
this.#editor?.monacoEditor?.executeEdits('', [
|
this.#editor?.monacoEditor?.executeEdits('', [
|
||||||
//TODO: media url
|
//TODO: Get the correct media URL
|
||||||
{
|
{
|
||||||
range: selection,
|
range: selection,
|
||||||
text: ``,
|
text: ``,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
this.#editor?.select({
|
||||||
if (!alt?.length) {
|
startColumn: selection.startColumn + 2,
|
||||||
this.#editor?.select({
|
endColumn: selection.startColumn + alt.length + 2, // +2 because of ![
|
||||||
startColumn: selection.startColumn + 1,
|
endLineNumber: selection.startLineNumber,
|
||||||
endColumn: selection.startColumn + 10,
|
startLineNumber: selection.startLineNumber,
|
||||||
endLineNumber: selection.startLineNumber,
|
});
|
||||||
startLineNumber: selection.startLineNumber,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(() => undefined)
|
.catch(() => undefined)
|
||||||
.finally(() => this._focusEditor());
|
.finally(() => this._focusEditor());
|
||||||
@@ -550,7 +547,7 @@ export class UmbInputMarkdownElement extends FormControlMixin(UmbLitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderPreview() {
|
renderPreview() {
|
||||||
if (this.preview) return;
|
if (!this.preview) return;
|
||||||
return html`<uui-scroll-container id="preview">
|
return html`<uui-scroll-container id="preview">
|
||||||
${unsafeHTML(
|
${unsafeHTML(
|
||||||
sanitizeHtml(marked.parse((this.value as string) || ''), {
|
sanitizeHtml(marked.parse((this.value as string) || ''), {
|
||||||
|
|||||||
Reference in New Issue
Block a user