From d75f5607c2e50678cef408073827a5e2c3907e53 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Tue, 16 May 2017 12:32:59 -0500 Subject: [PATCH] Fix edge case when no marks exist yet. --- ptk.nim | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ptk.nim b/ptk.nim index 7a7bb96..383b3c7 100644 --- a/ptk.nim +++ b/ptk.nim @@ -514,7 +514,8 @@ Options: let prevLastIdx = timeline.marks.getLastIndex() timeline.marks.add(newMark) timeline.writeMarks( - indices = @[prevLastIdx, timeline.marks.len - 1], + indices = if prevLastIdx < 0: @[0] + else: @[prevLastIdx, timeline.marks.len - 1], includeNotes = args["--verbose"]) saveTimeline(timeline, timelineLocation) @@ -526,7 +527,9 @@ Options: if args[""]: markToResumeIdx = timeline.marks.findById($args[""]) if markToResumeIdx == -1: exitErr "Cannot find a mark matching " & $args[""] - else: markToResumeIdx = timeline.marks.getLastIndex() + else: + markToResumeIdx = timeline.marks.getLastIndex() + if markToResumeIdx < 0: exitErr "No mark to resume." var markToResume = timeline.marks[markToResumeIdx] var newMark: Mark = ( @@ -553,7 +556,9 @@ Options: if args[""]: markIdx = timeline.marks.findById($args[""]) if markIdx == -1: exitErr "Cannot find a mark matching " & $args[""] - else: markIdx = timeline.marks.getLastIndex() + else: + markIdx = timeline.marks.getLastIndex() + if markIdx < 0: exitErr "No mark to amend." var mark = timeline.marks[markIdx]