From 88a95ad06b99043d496c7260846cc7252d7e1a57 Mon Sep 17 00:00:00 2001 From: Adam Boesch Date: Sun, 14 Sep 2014 13:07:30 -0500 Subject: [PATCH 1/6] Fix cursor so clicking the below the last line of text puts the cursor at the end of the last line. --- src/display-buffer.coffee | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/display-buffer.coffee b/src/display-buffer.coffee index d64af3270..37e8acfd4 100644 --- a/src/display-buffer.coffee +++ b/src/display-buffer.coffee @@ -661,7 +661,9 @@ class DisplayBuffer extends Model targetTop = pixelPosition.top targetLeft = pixelPosition.left defaultCharWidth = @defaultCharWidth - row = Math.floor(targetTop / @getLineHeightInPixels()) + rawRowCount = targetTop / @getLineHeightInPixels() + isLastRow = rawRowCount > @getLastRow() + row = Math.floor(rawRowCount) row = Math.min(row, @getLastRow()) row = Math.max(0, row) @@ -669,11 +671,14 @@ class DisplayBuffer extends Model column = 0 for token in @tokenizedLineForScreenRow(row).tokens charWidths = @getScopedCharWidths(token.scopeDescriptor) - for char in token.value - charWidth = charWidths[char] ? defaultCharWidth - break if targetLeft <= left + (charWidth / 2) - left += charWidth - column++ + if !isLastRow + for char in token.value + charWidth = charWidths[char] ? defaultCharWidth + break if targetLeft <= left + (charWidth / 2) + left += charWidth + column++ + else + column = token.value.length new Point(row, column) From 111b956f93d274bfc237c9c808ec0e60f150c80a Mon Sep 17 00:00:00 2001 From: Adam Boesch Date: Tue, 16 Sep 2014 21:18:59 -0500 Subject: [PATCH 2/6] Fix cursor not being able to move within the last line of text. --- src/display-buffer.coffee | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/display-buffer.coffee b/src/display-buffer.coffee index 37e8acfd4..71271d880 100644 --- a/src/display-buffer.coffee +++ b/src/display-buffer.coffee @@ -661,9 +661,8 @@ class DisplayBuffer extends Model targetTop = pixelPosition.top targetLeft = pixelPosition.left defaultCharWidth = @defaultCharWidth - rawRowCount = targetTop / @getLineHeightInPixels() - isLastRow = rawRowCount > @getLastRow() - row = Math.floor(rawRowCount) + row = Math.floor(targetTop / @getLineHeightInPixels()) + isLastRow = row > @getLastRow() row = Math.min(row, @getLastRow()) row = Math.max(0, row) From f81bc4b870b78a665773caf224d50b8db4b82c67 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 16 Oct 2014 17:01:18 -0700 Subject: [PATCH 3/6] Never break when past the last row --- src/display-buffer.coffee | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/display-buffer.coffee b/src/display-buffer.coffee index 71271d880..a56a0e275 100644 --- a/src/display-buffer.coffee +++ b/src/display-buffer.coffee @@ -662,7 +662,7 @@ class DisplayBuffer extends Model targetLeft = pixelPosition.left defaultCharWidth = @defaultCharWidth row = Math.floor(targetTop / @getLineHeightInPixels()) - isLastRow = row > @getLastRow() + pastLastRow = row > @getLastRow() row = Math.min(row, @getLastRow()) row = Math.max(0, row) @@ -670,14 +670,11 @@ class DisplayBuffer extends Model column = 0 for token in @tokenizedLineForScreenRow(row).tokens charWidths = @getScopedCharWidths(token.scopeDescriptor) - if !isLastRow - for char in token.value - charWidth = charWidths[char] ? defaultCharWidth - break if targetLeft <= left + (charWidth / 2) - left += charWidth - column++ - else - column = token.value.length + for char in token.value + charWidth = charWidths[char] ? defaultCharWidth + break if not pastLastRow and targetLeft <= left + (charWidth / 2) + left += charWidth + column++ new Point(row, column) From 8c136b18c27610bcfa57d566b28a110065cfbe37 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 16 Oct 2014 17:05:47 -0700 Subject: [PATCH 4/6] Set targetLeft to Infinity when past last row --- src/display-buffer.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/display-buffer.coffee b/src/display-buffer.coffee index a56a0e275..aa9c22737 100644 --- a/src/display-buffer.coffee +++ b/src/display-buffer.coffee @@ -662,7 +662,7 @@ class DisplayBuffer extends Model targetLeft = pixelPosition.left defaultCharWidth = @defaultCharWidth row = Math.floor(targetTop / @getLineHeightInPixels()) - pastLastRow = row > @getLastRow() + targetLeft = Infinity if row > @getLastRow() row = Math.min(row, @getLastRow()) row = Math.max(0, row) @@ -672,7 +672,7 @@ class DisplayBuffer extends Model charWidths = @getScopedCharWidths(token.scopeDescriptor) for char in token.value charWidth = charWidths[char] ? defaultCharWidth - break if not pastLastRow and targetLeft <= left + (charWidth / 2) + break if targetLeft <= left + (charWidth / 2) left += charWidth column++ From 5069a5b48bd39544092466be2effc212f4852b9d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 16 Oct 2014 17:16:18 -0700 Subject: [PATCH 5/6] Add spec for clicking past last line --- spec/text-editor-component-spec.coffee | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/text-editor-component-spec.coffee b/spec/text-editor-component-spec.coffee index 2144eb988..2b212b6c9 100644 --- a/spec/text-editor-component-spec.coffee +++ b/spec/text-editor-component-spec.coffee @@ -1230,6 +1230,22 @@ describe "TextEditorComponent", -> beforeEach -> linesNode = componentNode.querySelector('.lines') + describe "when the mouse is clicked below the last line", -> + it "moves the cursor to the end of file buffer position", -> + editor.setText('foo') + editor.setCursorBufferPosition([0, 0]) + height = 4.5 * lineHeightInPixels + wrapperNode.style.height = height + 'px' + wrapperNode.style.width = 10 * charWidth + 'px' + component.measureHeightAndWidth() + nextAnimationFrame() + + coordinates = clientCoordinatesForScreenPosition([0, 2]) + coordinates.clientY = height * 2 + linesNode.dispatchEvent(buildMouseEvent('mousedown', coordinates)) + nextAnimationFrame() + expect(editor.getCursorScreenPosition()).toEqual [0, 3] + describe "when a non-folded line is single-clicked", -> describe "when no modifier keys are held down", -> it "moves the cursor to the nearest screen position", -> From d6feb686c15de9de211c8d654d1780e3e4b5019a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 16 Oct 2014 17:17:33 -0700 Subject: [PATCH 6/6] Mention single click --- spec/text-editor-component-spec.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/text-editor-component-spec.coffee b/spec/text-editor-component-spec.coffee index 2b212b6c9..ac176c66d 100644 --- a/spec/text-editor-component-spec.coffee +++ b/spec/text-editor-component-spec.coffee @@ -1230,7 +1230,7 @@ describe "TextEditorComponent", -> beforeEach -> linesNode = componentNode.querySelector('.lines') - describe "when the mouse is clicked below the last line", -> + describe "when the mouse is single-clicked below the last line", -> it "moves the cursor to the end of file buffer position", -> editor.setText('foo') editor.setCursorBufferPosition([0, 0])