Move cursor to description when editing
This commit is contained in:
parent
15c547fe5e
commit
038721177d
2 changed files with 28 additions and 11 deletions
|
|
@ -26,6 +26,7 @@ module TaskMachine.Task
|
||||||
, compareTasks
|
, compareTasks
|
||||||
-- * Formatting
|
-- * Formatting
|
||||||
, formatTask
|
, formatTask
|
||||||
|
, formatTaskHalves
|
||||||
, formatTasks
|
, formatTasks
|
||||||
, formatDate
|
, formatDate
|
||||||
, formatDue
|
, formatDue
|
||||||
|
|
@ -73,6 +74,23 @@ data Task = Task
|
||||||
, taskDescription :: Description
|
, taskDescription :: Description
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
|
-- | Convert a 'Task' to its string representation.
|
||||||
|
-- This string representation is split into a pre-description and a description part.
|
||||||
|
--
|
||||||
|
-- For further detail, see 'formatTask'
|
||||||
|
formatTaskHalves :: Task -> (String, String)
|
||||||
|
formatTaskHalves t =
|
||||||
|
( formatCompletion (taskCompletion t) ++ " "
|
||||||
|
++ maybeWithSpace formatPriority (taskPriority t)
|
||||||
|
++ maybeWithSpace formatDue(taskDue t)
|
||||||
|
++ maybeWithSpace formatCreated (taskCreated t)
|
||||||
|
, formatDescription (taskDescription t)
|
||||||
|
)
|
||||||
|
where
|
||||||
|
maybeWithSpace :: (a -> String) -> Maybe a -> String
|
||||||
|
maybeWithSpace _ Nothing = ""
|
||||||
|
maybeWithSpace f (Just a) = f a ++ " "
|
||||||
|
|
||||||
-- | Convert a 'Task' to its string representation, which can be parsed by 'pTask'.
|
-- | Convert a 'Task' to its string representation, which can be parsed by 'pTask'.
|
||||||
--
|
--
|
||||||
-- If this string representation is parsed using 'pTask', it should yield the original task,
|
-- If this string representation is parsed using 'pTask', it should yield the original task,
|
||||||
|
|
@ -81,16 +99,9 @@ data Task = Task
|
||||||
-- could include the text version of these in the beginning, i. e. @taskDescription = "(A) hello"@.
|
-- could include the text version of these in the beginning, i. e. @taskDescription = "(A) hello"@.
|
||||||
-- In that case, converting the task to a string and back yields a different result.
|
-- In that case, converting the task to a string and back yields a different result.
|
||||||
formatTask :: Task -> String
|
formatTask :: Task -> String
|
||||||
formatTask t
|
formatTask t =
|
||||||
= formatCompletion (taskCompletion t) ++ " "
|
let (predesc, desc) = formatTaskHalves t
|
||||||
++ maybeWithSpace formatPriority (taskPriority t)
|
in predesc ++ desc
|
||||||
++ maybeWithSpace formatDue(taskDue t)
|
|
||||||
++ maybeWithSpace formatCreated (taskCreated t)
|
|
||||||
++ formatDescription (taskDescription t)
|
|
||||||
where
|
|
||||||
maybeWithSpace :: (a -> String) -> Maybe a -> String
|
|
||||||
maybeWithSpace _ Nothing = ""
|
|
||||||
maybeWithSpace f (Just a) = f a ++ " "
|
|
||||||
|
|
||||||
-- | Convert a list of tasks to its string representation, which can be parsed by 'pTasks'.
|
-- | Convert a list of tasks to its string representation, which can be parsed by 'pTasks'.
|
||||||
formatTasks :: [Task] -> String
|
formatTasks :: [Task] -> String
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,13 @@ data EditState = ExistingTask | NewTask
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
taskEdit :: n -> Task -> EditState -> TaskEdit n
|
taskEdit :: n -> Task -> EditState -> TaskEdit n
|
||||||
taskEdit name task s = TaskEdit s $ B.editor name (Just 1) (formatTask task)
|
taskEdit name task s =
|
||||||
|
let (predesc, desc) = formatTaskHalves task
|
||||||
|
formattedTask = predesc ++ desc
|
||||||
|
cursor = length predesc
|
||||||
|
editor = B.editor name (Just 1) formattedTask
|
||||||
|
newEditor = B.applyEdit (T.moveCursor (0, cursor)) editor
|
||||||
|
in TaskEdit s newEditor
|
||||||
|
|
||||||
editState :: TaskEdit n -> EditState
|
editState :: TaskEdit n -> EditState
|
||||||
editState (TaskEdit s _) = s
|
editState (TaskEdit s _) = s
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue