MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / computeAutoIndent

Function computeAutoIndent

packages/core/src/widgets/codeEditor.ts:209–232  ·  view source on GitHub ↗
(
  lines: readonly string[],
  cursor: CursorPosition,
  tabSize: number = DEFAULT_TAB_SIZE,
)

Source from the content-addressed store, hash-verified

207 * @returns Indent string to prepend to new line
208 */
209export function computeAutoIndent(
210 lines: readonly string[],
211 cursor: CursorPosition,
212 tabSize: number = DEFAULT_TAB_SIZE,
213): string {
214 const currentLine = lines[cursor.line] ?? "";
215
216 // Match leading whitespace of current line
217 const match = currentLine.match(/^(\s*)/);
218 let indent = match ? (match[1] ?? "") : "";
219
220 // Check if line ends with opening brace/bracket
221 const trimmedBeforeCursor = currentLine.slice(0, cursor.column).trimEnd();
222 if (
223 trimmedBeforeCursor.endsWith("{") ||
224 trimmedBeforeCursor.endsWith("[") ||
225 trimmedBeforeCursor.endsWith("(") ||
226 trimmedBeforeCursor.endsWith(":")
227 ) {
228 indent += " ".repeat(tabSize);
229 }
230
231 return indent;
232}
233
234/**
235 * Indent lines in a range.

Callers 3

routeCodeEditorKeyDownFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected