mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-25 22:01:13 +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
|
||||
)}[${selectedText}]()${i.state.content.substring(end)}`;
|
||||
textarea.focus();
|
||||
setTimeout(() => (textarea.selectionEnd = end + 4), 10);
|
||||
setTimeout(() => (textarea.selectionEnd = end + 5), 10);
|
||||
} else {
|
||||
i.state.content += '[]()';
|
||||
textarea.focus();
|
||||
setTimeout(() => (textarea.selectionEnd -= 1), 10);
|
||||
setTimeout(() => (textarea.selectionEnd -= 0), 10);
|
||||
}
|
||||
i.setState(i.state);
|
||||
}
|
||||
|
@ -435,7 +435,15 @@ export class MarkdownTextArea extends Component<
|
|||
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) {
|
||||
this.state.content = '';
|
||||
}
|
||||
|
@ -447,12 +455,12 @@ export class MarkdownTextArea extends Component<
|
|||
let selectedText = this.state.content.substring(start, end);
|
||||
this.state.content = `${this.state.content.substring(
|
||||
0,
|
||||
start - 1
|
||||
start
|
||||
)}${beforeChars}${selectedText}${afterChars}${this.state.content.substring(
|
||||
end + 1
|
||||
end
|
||||
)}`;
|
||||
} else {
|
||||
this.state.content += `${beforeChars}___${afterChars}`;
|
||||
this.state.content += `${beforeChars}${emptyChars}${afterChars}`;
|
||||
}
|
||||
this.setState(this.state);
|
||||
setTimeout(() => {
|
||||
|
@ -482,17 +490,17 @@ export class MarkdownTextArea extends Component<
|
|||
|
||||
handleInsertList(i: MarkdownTextArea, event: any) {
|
||||
event.preventDefault();
|
||||
i.simpleInsert('-');
|
||||
i.simpleBeginningofLine('-');
|
||||
}
|
||||
|
||||
handleInsertQuote(i: MarkdownTextArea, event: any) {
|
||||
event.preventDefault();
|
||||
i.simpleInsert('>');
|
||||
i.simpleBeginningofLine('>');
|
||||
}
|
||||
|
||||
handleInsertHeader(i: MarkdownTextArea, event: any) {
|
||||
event.preventDefault();
|
||||
i.simpleInsert('#');
|
||||
i.simpleBeginningofLine('#');
|
||||
}
|
||||
|
||||
handleInsertSubscript(i: MarkdownTextArea, event: any) {
|
||||
|
|
Loading…
Reference in a new issue