({
api,
selectedText,
selection,
prefix,
suffix = prefix,
}: {
api: TextAreaTextApi;
selectedText: string;
selection: TextRange;
prefix: string;
suffix?: string;
})
| 127 | } |
| 128 | |
| 129 | export function executeCommand({ |
| 130 | api, |
| 131 | selectedText, |
| 132 | selection, |
| 133 | prefix, |
| 134 | suffix = prefix, |
| 135 | }: { |
| 136 | api: TextAreaTextApi; |
| 137 | selectedText: string; |
| 138 | selection: TextRange; |
| 139 | prefix: string; |
| 140 | suffix?: string; |
| 141 | }) { |
| 142 | if ( |
| 143 | selectedText.length >= prefix.length + suffix.length && |
| 144 | selectedText.startsWith(prefix) && |
| 145 | selectedText.endsWith(suffix) |
| 146 | ) { |
| 147 | api.replaceSelection(selectedText.slice(prefix.length, suffix.length ? -suffix.length : undefined)); |
| 148 | api.setSelectionRange({ start: selection.start - prefix.length, end: selection.end - prefix.length }); |
| 149 | } else { |
| 150 | api.replaceSelection(`${prefix}${selectedText}${suffix}`); |
| 151 | api.setSelectionRange({ start: selection.start + prefix.length, end: selection.end + prefix.length }); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | export type AlterLineFunction = (line: string, index: number) => string; |
| 156 |
no test coverage detected
searching dependent graphs…