File tree Expand file tree Collapse file tree 2 files changed +17
-12
lines changed
Expand file tree Collapse file tree 2 files changed +17
-12
lines changed Original file line number Diff line number Diff line change 5050--- @param line string
5151--- @return integer
5252function M .get_start_col (line )
53- local tabwidth = vim .opt .tabstop :get ()
54- local count = 1 -- 1 indexed
55- for i = 1 , # line do
56- local c = line :sub (i , i )
57- if c == " \t " then
58- count = math.floor ((count + tabwidth ) / tabwidth ) * tabwidth
59- elseif c == " " then
60- count = count + 1
61- else
62- break
63- end
53+ if not line or line == " " then
54+ return 1
6455 end
65- return count
56+ local first = line :find (" %S" )
57+ if not first then
58+ return 1
59+ end
60+ return first
6661end
6762
6863return M
Original file line number Diff line number Diff line change @@ -74,5 +74,15 @@ describe("lines", function()
7474 local indent = lines .get_start_col (" local line = lines.get_indent()" )
7575 assert .equals (3 , indent )
7676 end )
77+
78+ it (" treats tabs as single characters" , function ()
79+ local indent = lines .get_start_col (" \t local line = lines.get_indent()" )
80+ assert .equals (2 , indent )
81+ end )
82+
83+ it (" falls back to the first column when the line is blank" , function ()
84+ local indent = lines .get_start_col (" " )
85+ assert .equals (1 , indent )
86+ end )
7787 end )
7888end )
You can’t perform that action at this time.
0 commit comments