• R/O
  • SSH
  • HTTPS

edmaru: コミット


コミットメタ情報

リビジョン43 (tree)
日時2007-04-20 20:59:59
作者bluedwarf

ログメッセージ

New method that converts logical cursor position to physical one.

変更サマリ

差分

--- ncurses/ncurses_window.rb (revision 42)
+++ ncurses/ncurses_window.rb (revision 43)
@@ -60,10 +60,55 @@
6060 refresh
6161 end
6262
63+ def cursor_logical_to_physical(l_cursor)
64+ p_cursor = Edmaru::Cursor.new
65+
66+ if l_cursor.row == 0
67+ if l_cursor.column == 0
68+ p_cursor.row = p_cursor.column = 0
69+ elsif (l_cursor.column % @max_column) == 0 &&
70+ l_cursor.column == @buffer.lines[0].size
71+ p_cursor.row = l_cursor.column / @max_column - 1
72+ p_cursor.column = @max_column
73+ else
74+ p_cursor.row = l_cursor.column / @max_column
75+ p_cursor.column = l_cursor.column % @max_column
76+ end
77+ else
78+ p_cursor.row = 0
79+
80+ l_cursor.row.times{ |n|
81+ if @buffer.lines[n].size == 0
82+ p_cursor.row += 1
83+ elsif (@buffer.lines[n].size % @max_column) == 0
84+ p_cursor.row += (@buffer.lines[n].size / @max_column)
85+ else
86+ p_cursor.row += (@buffer.lines[n].size / @max_column + 1)
87+ end
88+ }
89+
90+ if l_cursor.column == 0
91+ p_cursor.column = 0
92+ elsif (l_cursor.column & @max_column) == 0 &&
93+ l_cursor.column == @buffer.lines[l_cursor.row].size
94+ p_cursor.row += (l_cursor.column / @max_column - 1)
95+ p_cursor.column = @max_column
96+ else
97+ p_cursor.row += (l_cursor.column / @max_column)
98+ p_cursor.column = l_cursor.column % @max_column
99+ end
100+ end
101+
102+ return p_cursor
103+ end
104+
105+ def cursor_physical_to_logical(p_cursor)
106+
107+ end
108+
63109 #Refresh hte cursor. Move the cursor to the correct position.
64110 def refresh_cursor
65111 return if @offscreen == nil
66- return if @l_to_p == nil
67112 @p_start_row = 0 if @p_start_row == nil
68113
69114 #There is no need to update cursor if this window is not
@@ -70,19 +115,9 @@
70115 #focused.
71116 return if !@focused
72117
73- p_cursor_row = @l_to_p[@cursor.row]
74- if @cursor.column == 0
75- p_cursor_col = 0
76- elsif (@cursor.column % @max_column) == 0 &&
77- @cursor.column == @buffer.lines[@cursor.row].size
78- p_cursor_row += (@cursor.column / @max_column - 1)
79- p_cursor_col = @max_column
80- else
81- p_cursor_row += (@cursor.column / @max_column)
82- p_cursor_col = @cursor.column % @max_column
83- end
118+ p_cursor = cursor_logical_to_physical(@cursor)
84119
85- if (p_cursor_row - @p_start_row) >= @max_row
120+ if (p_cursor.row - @p_start_row) >= @max_row
86121 # scroll down
87122 if @max_row != 1
88123 @p_start_row += (@max_row / 2)
@@ -92,7 +127,7 @@
92127
93128 refresh
94129 return
95- elsif (p_cursor_row - @p_start_row) < 0 && @p_start_row > 0
130+ elsif (p_cursor.row - @p_start_row) < 0 && @p_start_row > 0
96131 # scroll up
97132 if @max_row != 1
98133 @p_start_row -= (@max_row / 2)
@@ -105,8 +140,8 @@
105140 return
106141 end
107142
108- @win.move(p_cursor_row - @p_start_row, p_cursor_col)
109-
143+ @win.move(p_cursor.row - @p_start_row, p_cursor.column)
144+
110145 @modeline.set_element_text("cursor-position",
111146 "(#{@cursor.row},#{@cursor.column})")
112147
@@ -116,17 +151,12 @@
116151 #Redraw this window.
117152 def refresh
118153 @offscreen = Array.new
119- @l_to_p = Array.new # logical line to physical line
120154 @p_start_row = 0 if @p_start_row == nil
121155
122- physical_row = 0
123156 @buffer.lines.each{ |line|
124157 line = line.clone
125- @l_to_p.push physical_row
126158
127159 while(true)
128- physical_row += 1
129-
130160 if line.size == 0
131161 @offscreen.push("")
132162 break
旧リポジトリブラウザで表示