MCPcopy Create free account
hub / github.com/uiwjs/react-md-editor / executeCommand

Function executeCommand

core/src/utils/markdownUtils.ts:129–153  ·  view source on GitHub ↗
({
  api,
  selectedText,
  selection,
  prefix,
  suffix = prefix,
}: {
  api: TextAreaTextApi;
  selectedText: string;
  selection: TextRange;
  prefix: string;
  suffix?: string;
})

Source from the content-addressed store, hash-verified

127}
128
129export 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
155export type AlterLineFunction = (line: string, index: number) => string;
156

Callers 11

issue.tsxFile · 0.90
italic.tsxFile · 0.90
code.tsxFile · 0.90
bold.tsxFile · 0.90
comment.tsxFile · 0.90
link.tsxFile · 0.90
headingExecuteFunction · 0.90
table.tsxFile · 0.90
strikeThrough.tsxFile · 0.90
hr.tsxFile · 0.90
image.tsxFile · 0.90

Calls 2

replaceSelectionMethod · 0.80
setSelectionRangeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…