From caf34d6a3a4f70ab12eb77883f108dab114578c1 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 29 Apr 2013 10:22:07 -0600 Subject: [PATCH] EditSession.selectMarker checks if the marker is valid Also, it returns the selected range if it's valid, and otherwise returns a falsy value. This has more utility than just true/false. --- spec/app/edit-session-spec.coffee | 16 ++++++++++++---- src/app/edit-session.coffee | 9 ++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 94a177ce9..a8b115601 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -744,10 +744,18 @@ describe "EditSession", -> expect(editSession.lineForScreenRow(1).fold).toBeDefined() describe ".selectMarker(marker)", -> - it "selects the marker's range and returns true", -> - marker = editSession.markBufferRange([[0, 1], [3, 3]]) - expect(editSession.selectMarker(marker)).toBeTruthy() - expect(editSession.getSelectedBufferRange()).toEqual [[0, 1], [3, 3]] + describe "if the marker is valid", -> + it "selects the marker's range and returns the selected range", -> + marker = editSession.markBufferRange([[0, 1], [3, 3]]) + expect(editSession.selectMarker(marker)).toEqual [[0, 1], [3, 3]] + expect(editSession.getSelectedBufferRange()).toEqual [[0, 1], [3, 3]] + + describe "if the marker is invalid", -> + it "does not change the selection and returns a falsy value", -> + marker = editSession.markBufferRange([[0, 1], [3, 3]]) + marker.destroy() + expect(editSession.selectMarker(marker)).toBeFalsy() + expect(editSession.getSelectedBufferRange()).toEqual [[0, 0], [0, 0]] describe ".addSelectionBelow()", -> describe "when the selection is non-empty", -> diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 2801b4c2a..752d68f0e 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -1411,11 +1411,10 @@ class EditSession @getLastSelection().expandOverWord() selectMarker: (marker) -> - if bufferRange = marker.getBufferRange() - @setSelectedBufferRange(bufferRange) - true - else - false + if marker.isValid() + range = marker.getBufferRange() + @setSelectedBufferRange(range) + range # Public: Given a buffer position, this finds all markers that contain the position. #