Prechádzať zdrojové kódy

fix: normalize lf enter in tui input

paoloanzn 2 mesiacov pred
rodič
commit
c1f9b3e7d3
1 zmenil súbory, kde vykonal 8 pridanie a 4 odobranie
  1. 8 4
      src/ink/parse-keypress.ts

+ 8 - 4
src/ink/parse-keypress.ts

@@ -210,6 +210,10 @@ function inputToString(input: Buffer | string): string {
   }
 }
 
+function splitTextToken(value: string): string[] {
+  return value.match(/\r\n|[\r\n]|[^\r\n]+/g) ?? []
+}
+
 export function parseMultipleKeypresses(
   prevState: KeyParseState,
   input: Buffer | string | null = '',
@@ -278,7 +282,9 @@ export function parseMultipleKeypresses(
         const mouse = parseMouseEvent(resynthesized)
         keys.push(mouse ?? parseKeypress(resynthesized))
       } else {
-        keys.push(parseKeypress(token.value))
+        for (const chunk of splitTextToken(token.value)) {
+          keys.push(parseKeypress(chunk))
+        }
       }
     }
   }
@@ -698,11 +704,9 @@ function parseKeypress(s: string = ''): ParsedKey {
     return createNavKey(s, 'mouse', false)
   }
 
-  if (s === '\r') {
+  if (s === '\r' || s === '\n' || s === '\r\n') {
     key.raw = undefined
     key.name = 'return'
-  } else if (s === '\n') {
-    key.name = 'enter'
   } else if (s === '\t') {
     key.name = 'tab'
   } else if (s === '\b' || s === '\x1b\b') {