@@ -110,9 +110,9 @@ export const webviewMessageHandler = async (
110110 const { messageIndex } = findMessageIndices ( messageTs , currentCline )
111111 if ( messageIndex !== - 1 ) {
112112 // Find the last checkpoint before this message
113- const checkpoints = currentCline . clineMessages
114- . filter ( ( msg ) => msg . say === "checkpoint_saved" && msg . ts < messageTs )
115- . sort ( ( a , b ) => b . ts - a . ts )
113+ const checkpoints = currentCline . clineMessages . filter (
114+ ( msg ) => msg . say === "checkpoint_saved" && msg . ts > messageTs ,
115+ )
116116
117117 hasCheckpoint = checkpoints . length > 0
118118 } else {
@@ -153,19 +153,19 @@ export const webviewMessageHandler = async (
153153 // If checkpoint restoration is requested, find and restore to the last checkpoint before this message
154154 if ( restoreCheckpoint ) {
155155 // Find the last checkpoint before this message
156- const checkpoints = currentCline . clineMessages
157- . filter ( ( msg ) => msg . say === "checkpoint_saved" && msg . ts < messageTs )
158- . sort ( ( a , b ) => b . ts - a . ts )
156+ const checkpoints = currentCline . clineMessages . filter (
157+ ( msg ) => msg . say === "checkpoint_saved" && msg . ts > messageTs ,
158+ )
159159
160- const lastCheckpoint = checkpoints [ 0 ]
160+ const nextCheckpoint = checkpoints [ 0 ]
161161
162- if ( lastCheckpoint && lastCheckpoint . text ) {
162+ if ( nextCheckpoint && nextCheckpoint . text ) {
163163 await handleCheckpointRestoreOperation ( {
164164 provider,
165165 currentCline,
166166 messageTs : targetMessage . ts ! ,
167167 messageIndex,
168- checkpoint : { hash : lastCheckpoint . text } ,
168+ checkpoint : { hash : nextCheckpoint . text } ,
169169 operation : "delete" ,
170170 } )
171171 } else {
@@ -221,9 +221,9 @@ export const webviewMessageHandler = async (
221221 const { messageIndex } = findMessageIndices ( messageTs , currentCline )
222222 if ( messageIndex !== - 1 ) {
223223 // Find the last checkpoint before this message
224- const checkpoints = currentCline . clineMessages
225- . filter ( ( msg ) => msg . say === "checkpoint_saved" && msg . ts < messageTs )
226- . sort ( ( a , b ) => b . ts - a . ts )
224+ const checkpoints = currentCline . clineMessages . filter (
225+ ( msg ) => msg . say === "checkpoint_saved" && msg . ts > messageTs ,
226+ )
227227
228228 hasCheckpoint = checkpoints . length > 0
229229 } else {
@@ -274,19 +274,19 @@ export const webviewMessageHandler = async (
274274 // If checkpoint restoration is requested, find and restore to the last checkpoint before this message
275275 if ( restoreCheckpoint ) {
276276 // Find the last checkpoint before this message
277- const checkpoints = currentCline . clineMessages
278- . filter ( ( msg ) => msg . say === "checkpoint_saved" && msg . ts < messageTs )
279- . sort ( ( a , b ) => b . ts - a . ts )
277+ const checkpoints = currentCline . clineMessages . filter (
278+ ( msg ) => msg . say === "checkpoint_saved" && msg . ts > messageTs ,
279+ )
280280
281- const lastCheckpoint = checkpoints [ 0 ]
281+ const nextCheckpoint = checkpoints [ 0 ]
282282
283- if ( lastCheckpoint && lastCheckpoint . text ) {
283+ if ( nextCheckpoint && nextCheckpoint . text ) {
284284 await handleCheckpointRestoreOperation ( {
285285 provider,
286286 currentCline,
287287 messageTs : targetMessage . ts ! ,
288288 messageIndex,
289- checkpoint : { hash : lastCheckpoint . text } ,
289+ checkpoint : { hash : nextCheckpoint . text } ,
290290 operation : "edit" ,
291291 editData : {
292292 editedContent,
0 commit comments