mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-29 15:51:14 +00:00
parent
bf52dec0a1
commit
9dcc998878
1 changed files with 19 additions and 11 deletions
|
@ -422,11 +422,11 @@ export class MarkdownTextArea extends Component<
|
||||||
start
|
start
|
||||||
)}[${selectedText}]()${i.state.content.substring(end)}`;
|
)}[${selectedText}]()${i.state.content.substring(end)}`;
|
||||||
textarea.focus();
|
textarea.focus();
|
||||||
setTimeout(() => (textarea.selectionEnd = end + 4), 10);
|
setTimeout(() => (textarea.selectionEnd = end + 5), 10);
|
||||||
} else {
|
} else {
|
||||||
i.state.content += '[]()';
|
i.state.content += '[]()';
|
||||||
textarea.focus();
|
textarea.focus();
|
||||||
setTimeout(() => (textarea.selectionEnd -= 1), 10);
|
setTimeout(() => (textarea.selectionEnd -= 0), 10);
|
||||||
}
|
}
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
}
|
}
|
||||||
|
@ -435,7 +435,15 @@ export class MarkdownTextArea extends Component<
|
||||||
this.simpleSurroundBeforeAfter(chars, chars);
|
this.simpleSurroundBeforeAfter(chars, chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
simpleSurroundBeforeAfter(beforeChars: string, afterChars: string) {
|
simpleBeginningofLine(chars: string) {
|
||||||
|
this.simpleSurroundBeforeAfter(`${chars} `, '', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
simpleSurroundBeforeAfter(
|
||||||
|
beforeChars: string,
|
||||||
|
afterChars: string,
|
||||||
|
emptyChars: string = '___'
|
||||||
|
) {
|
||||||
if (!this.state.content) {
|
if (!this.state.content) {
|
||||||
this.state.content = '';
|
this.state.content = '';
|
||||||
}
|
}
|
||||||
|
@ -447,12 +455,12 @@ export class MarkdownTextArea extends Component<
|
||||||
let selectedText = this.state.content.substring(start, end);
|
let selectedText = this.state.content.substring(start, end);
|
||||||
this.state.content = `${this.state.content.substring(
|
this.state.content = `${this.state.content.substring(
|
||||||
0,
|
0,
|
||||||
start - 1
|
start
|
||||||
)}${beforeChars}${selectedText}${afterChars}${this.state.content.substring(
|
)}${beforeChars}${selectedText}${afterChars}${this.state.content.substring(
|
||||||
end + 1
|
end
|
||||||
)}`;
|
)}`;
|
||||||
} else {
|
} else {
|
||||||
this.state.content += `${beforeChars}___${afterChars}`;
|
this.state.content += `${beforeChars}${emptyChars}${afterChars}`;
|
||||||
}
|
}
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
@ -482,17 +490,17 @@ export class MarkdownTextArea extends Component<
|
||||||
|
|
||||||
handleInsertList(i: MarkdownTextArea, event: any) {
|
handleInsertList(i: MarkdownTextArea, event: any) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
i.simpleInsert('-');
|
i.simpleBeginningofLine('-');
|
||||||
}
|
}
|
||||||
|
|
||||||
handleInsertQuote(i: MarkdownTextArea, event: any) {
|
handleInsertQuote(i: MarkdownTextArea, event: any) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
i.simpleInsert('>');
|
i.simpleBeginningofLine('>');
|
||||||
}
|
}
|
||||||
|
|
||||||
handleInsertHeader(i: MarkdownTextArea, event: any) {
|
handleInsertHeader(i: MarkdownTextArea, event: any) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
i.simpleInsert('#');
|
i.simpleBeginningofLine('#');
|
||||||
}
|
}
|
||||||
|
|
||||||
handleInsertSubscript(i: MarkdownTextArea, event: any) {
|
handleInsertSubscript(i: MarkdownTextArea, event: any) {
|
||||||
|
|
Loading…
Reference in a new issue