From 3134bfda95521bdde6b09197bc3443b014211c14 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 2 Jun 2014 18:37:21 +0900 Subject: [PATCH] Update selections when the font size or font family change --- spec/editor-component-spec.coffee | 14 ++++++++++++++ src/lines-component.coffee | 4 ++-- src/selections-component.coffee | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index 1a1d2daa0..b9c469829 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -476,6 +476,20 @@ describe "EditorComponent", -> selectionNode = node.querySelector('.region') expect(selectionNode.offsetTop).toBe editor.getLineHeightInPixels() + it "updates selections when the font size changes", -> + editor.setSelectedBufferRange([[1, 6], [1, 10]]) + component.setFontSize(10) + selectionNode = node.querySelector('.region') + expect(selectionNode.offsetTop).toBe editor.getLineHeightInPixels() + expect(selectionNode.offsetLeft).toBe 6 * editor.getDefaultCharWidth() + + it "updates selections when the font family changes", -> + editor.setSelectedBufferRange([[1, 6], [1, 10]]) + component.setFontFamily('sans-serif') + selectionNode = node.querySelector('.region') + expect(selectionNode.offsetTop).toBe editor.getLineHeightInPixels() + expect(selectionNode.offsetLeft).toBe editor.pixelPositionForScreenPosition([1, 6]).left + describe "hidden input field", -> it "renders the hidden input field at the position of the last cursor if the cursor is on screen and the editor is focused", -> editor.setVerticalScrollMargin(0) diff --git a/src/lines-component.coffee b/src/lines-component.coffee index 9b8aa2cc5..216129ac3 100644 --- a/src/lines-component.coffee +++ b/src/lines-component.coffee @@ -15,14 +15,14 @@ LinesComponent = React.createClass render: -> if @isMounted() - {editor, selectionScreenRanges, scrollTop, scrollLeft, scrollHeight, scrollWidth, lineHeightInPixels, scrollViewHeight} = @props + {editor, selectionScreenRanges, scrollTop, scrollLeft, scrollHeight, scrollWidth, lineHeightInPixels, defaultCharWidth, scrollViewHeight} = @props style = height: Math.max(scrollHeight, scrollViewHeight) width: scrollWidth WebkitTransform: "translate3d(#{-scrollLeft}px, #{-scrollTop}px, 0px)" div {className: 'lines', style}, - SelectionsComponent({editor, selectionScreenRanges, lineHeightInPixels}) if @isMounted() + SelectionsComponent({editor, selectionScreenRanges, lineHeightInPixels, defaultCharWidth}) if @isMounted() componentWillMount: -> @measuredLines = new WeakSet diff --git a/src/selections-component.coffee b/src/selections-component.coffee index 9a7122b9c..0d4484421 100644 --- a/src/selections-component.coffee +++ b/src/selections-component.coffee @@ -22,4 +22,4 @@ SelectionsComponent = React.createClass @selectionRanges = {} shouldComponentUpdate: (newProps) -> - not isEqualForProperties(newProps, @props, 'selectionScreenRanges', 'lineHeightInPixels') + not isEqualForProperties(newProps, @props, 'selectionScreenRanges', 'lineHeightInPixels', 'defaultCharWidth')