add preferredColumn field to app type

This commit is contained in:
2024-10-18 06:44:45 +01:00
parent 92b834427c
commit 5f4be185e8
4 changed files with 27 additions and 7 deletions

View File

@@ -4,8 +4,13 @@ struct
{ buffer: LineGap.t { buffer: LineGap.t
, windowWidth: int , windowWidth: int
, windowHeight: int , windowHeight: int
(* line to start drawing from *)
, startLine: int , startLine: int
(* absolute index of movable cursor *)
, cursorIdx: int , cursorIdx: int
(* when moving cursor up or down a line,
* move to this column if possible *)
, preferredColumn: int
} }
fun init (buffer, windowWidth, windowHeight) : app_type = fun init (buffer, windowWidth, windowHeight) : app_type =
@@ -14,5 +19,6 @@ struct
, windowHeight = windowHeight , windowHeight = windowHeight
, startLine = 0 , startLine = 0
, cursorIdx = 0 , cursorIdx = 0
, preferredColumn = 0
} }
end end

View File

@@ -8,7 +8,7 @@ struct
fun resizeText (app: app_type, newWidth, newHeight) = fun resizeText (app: app_type, newWidth, newHeight) =
let let
val {buffer, windowWidth, windowHeight, startLine, cursorIdx} = app val {buffer, windowWidth, windowHeight, startLine, cursorIdx, ...} = app
val newBuffer = LineGap.goToLine (startLine, buffer) val newBuffer = LineGap.goToLine (startLine, buffer)
val drawMsg = TextBuilder.build val drawMsg = TextBuilder.build
@@ -21,7 +21,7 @@ struct
fun moveRight (app: app_type) = fun moveRight (app: app_type) =
let let
val {buffer, windowWidth, windowHeight, startLine, cursorIdx} = app val {buffer, windowWidth, windowHeight, startLine, cursorIdx, ...} = app
(* move LineGap to cursorIdx, which is necessary for finding newCursorIdx *) (* move LineGap to cursorIdx, which is necessary for finding newCursorIdx *)
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
@@ -39,7 +39,7 @@ struct
fun moveLeft (app: app_type) = fun moveLeft (app: app_type) =
let let
val {buffer, windowWidth, windowHeight, startLine, cursorIdx} = app val {buffer, windowWidth, windowHeight, startLine, cursorIdx, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
val cursorIdx = Cursor.viH (buffer, cursorIdx) val cursorIdx = Cursor.viH (buffer, cursorIdx)

View File

@@ -4,27 +4,41 @@ struct
fun bufferAndSize (app: app_type, newBuffer, newWidth, newHeight) = fun bufferAndSize (app: app_type, newBuffer, newWidth, newHeight) =
let let
val {buffer = _, windowWidth = _, windowHeight = _, startLine, cursorIdx} = val
app { buffer = _
, windowWidth = _
, windowHeight = _
, startLine
, cursorIdx
, preferredColumn
} = app
in in
{ buffer = newBuffer { buffer = newBuffer
, windowWidth = newWidth , windowWidth = newWidth
, windowHeight = newHeight , windowHeight = newHeight
, startLine = startLine , startLine = startLine
, cursorIdx = cursorIdx , cursorIdx = cursorIdx
, preferredColumn = preferredColumn
} }
end end
fun bufferAndCursorIdx (app: app_type, newBuffer, newCursorIdx) = fun bufferAndCursorIdx (app: app_type, newBuffer, newCursorIdx) =
let let
val {buffer = _, cursorIdx = _, windowWidth, windowHeight, startLine} = val
app { buffer = _
, cursorIdx = _
, windowWidth
, windowHeight
, startLine
, preferredColumn
} = app
in in
{ buffer = newBuffer { buffer = newBuffer
, cursorIdx = newCursorIdx , cursorIdx = newCursorIdx
, windowWidth = windowWidth , windowWidth = windowWidth
, windowHeight = windowHeight , windowHeight = windowHeight
, startLine = startLine , startLine = startLine
, preferredColumn = preferredColumn
} }
end end
end end

BIN
shf

Binary file not shown.