emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/typescript-mode 4235b47a38 060/222: Fix indent for lines w


From: ELPA Syncer
Subject: [nongnu] elpa/typescript-mode 4235b47a38 060/222: Fix indent for lines which starts with tabs.
Date: Sun, 6 Feb 2022 16:59:16 -0500 (EST)

branch: elpa/typescript-mode
commit 4235b47a389bf04a95fa54e59695f60599dc918b
Author: Jostein Kjønigsen <jostein@kjonigsen.net>
Commit: Jostein Kjønigsen <jostein@kjonigsen.net>

    Fix indent for lines which starts with tabs.
    
    This closes https://github.com/ananthakumaran/typescript.el/issues/37
---
 typescript-mode-tests.el | 37 ++++++++++++++++++++++++++-----------
 typescript-mode.el       | 12 ++----------
 2 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/typescript-mode-tests.el b/typescript-mode-tests.el
index f1bd21be2a..000e9b3484 100644
--- a/typescript-mode-tests.el
+++ b/typescript-mode-tests.el
@@ -99,21 +99,36 @@ a severity set to WARNING, no rule name."
     (should (string-equal (nth 4 matches) "1"))
     (should (string-equal (nth 5 matches) "83"))))
 
-(ert-deftest correctly-accounts-wide-chars-as-1-char ()
+(ert-deftest correctly-indents-lines-with-wide-chars ()
   "Otsuka Ai and other multi-char users should be a happy to write typescript."
 
   (with-temp-buffer
-    (insert "大塚愛")
-    (should (equal 3 (typescript--current-column)))))
-
-(ert-deftest correctly-accounts-wide-chars-as-1-char-without-sideeffects ()
-  "Otsuka Ai and other multi-char users should be a happy to write typescript."
-
+    (ignore-errors (typescript-mode))
+    (insert "let x = '大塚愛'")
+    (let ((pos1 (current-column)))
+      (typescript-indent-line)
+      (let ((pos2 (current-column)))
+        (should (= pos1 pos2))))))
+
+(ert-deftest correctly-indents-lines-with-tabs ()
   (with-temp-buffer
-    (insert "大塚愛")
-    (let ((pos1 (typescript--current-column))
-          (pos2 (typescript--current-column)))
-      (should (equal pos1 pos2)))))
+    (ignore-errors (typescript-mode))
+
+    (insert "class Example {")
+    (newline-and-indent)
+    (insert "constructor() {")
+    (newline-and-indent)
+    (insert "const a = new Promise")
+
+    (should (= 29 (current-column)))
+    (typescript-indent-line)
+    (should (= 29 (current-column)))
+
+    ;; verify tab was used
+    (move-beginning-of-line nil)
+    (should (= 0 (current-column)))
+    (forward-char 1)
+    (should (= 8 (current-column)))))
 
 (provide 'typescript-mode-tests)
 
diff --git a/typescript-mode.el b/typescript-mode.el
index 12840a00f1..c8866839e5 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -1795,14 +1795,6 @@ nil."
            (+ typescript-indent-level typescript-expr-indent-offset))
           (t 0))))
 
-(defun typescript--current-column ()
-  "Unicode aware version of `CURRENT-COLUMN' which correctly accounts for wide 
characters."
-
-  (save-excursion
-    (let ((end (point)))
-      (move-beginning-of-line nil)
-      (- end (point)))))
-
 (defun typescript-indent-line ()
   "Indent the current line as typescript."
   (interactive)
@@ -1810,9 +1802,9 @@ nil."
     (widen)
     (let* ((parse-status
             (save-excursion (syntax-ppss (point-at-bol))))
-           (offset (- (typescript--current-column) (current-indentation))))
+           (offset (- (current-column) (current-indentation))))
       (indent-line-to (typescript--proper-indentation parse-status))
-      (when (> offset 0) (forward-char offset)))))
+      (when (> offset 0) (move-to-column (+ offset (current-indentation)))))))
 
 ;;; Filling
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]