Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TextEditor::pixelRectForScreenRange instead of Marker::getPixelRange #138

Merged
merged 5 commits into from
Oct 5, 2015
Merged

Use TextEditor::pixelRectForScreenRange instead of Marker::getPixelRange #138

merged 5 commits into from
Oct 5, 2015

Conversation

as-cii
Copy link
Contributor

@as-cii as-cii commented Sep 25, 2015

This replaces Marker::getPixelRange with TextEditor::pixelRectForScreenRange, because the former was not part of the public API and will, therefore, be dropped in the next version of Atom (see atom/atom#8905 for further information).

Please, note that starting from the next version we're going to deprecate all those methods in TextEditor that refer to pixel coordinates (e.g. ::setScrollTop, ::pixelPositionForScreenPosition, ::pixelRectForScreenRange, etc.). You will still be able to use them, but we discourage it as they might disappear in a future version. These methods will be moved to TextEditorElement and, therefore, we recommend using those ones instead.

Unfortunately, I wasn't able to verify against some specs that the change I applied in this PR worked correctly. However, it seems to be fine from a cursory manual test.

Please, let me know if I can improve this somehow. Thanks! 🙇

/cc: @thomaslindstrom

@philipgiuliani
Copy link

Maybe you should also change the engine in the package.json so users with current versions won't get the next package release.

@as-cii
Copy link
Contributor Author

as-cii commented Sep 26, 2015

Maybe you should also change the engine in the package.json so users with current versions won't get the next package release.

This should actually be a non-breaking change, because we had TextEditor::pixelRectForScreenRange back in Atom 1.0.2. Therefore, I think we can keep the current version: once this repo will start moving to the corresponding methods in TextEditorElement, the engine version should definitely be ⬆️ bumped. 👍

Thank you for taking the time to review this! 🙇

@thomaslindstrom
Copy link
Owner

Hi, @as-cii! Thanks for keeping an eye out. I did some tests, and it works great except for in a case where there are more than one color value (?) on the same line. This screenshot is from lib/modules/SmartColor.coffee.

screen shot 2015-09-26 at 22 03 42

@as-cii
Copy link
Contributor Author

as-cii commented Sep 28, 2015

@thomaslindstrom: for some reason I assumed pixelRectForScreenRange returned a ::right position, but it doesn't.

This should now work properly: please have one last look 👀. Thanks!

_cursorPosition = Cursor.getPixelRect()
_cursorPosition.left = _selectionPosition.end.left - ((_selectionPosition.end.left - _selectionPosition.start.left) / 2)
_cursorPosition.left = right - ((right - left) / 2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just _cursorPosition.left = right - (width / 2)? :) Isn't width the same as (right - left)? because right = left + width... Maybe i'm wrong again... 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely a good point! 👍 Thanks!

@as-cii
Copy link
Contributor Author

as-cii commented Oct 3, 2015

@thomaslindstrom: I think this is good to go now. 🎆

@@ -357,9 +357,10 @@
# the middle of the selection range
# TODO: There can be lines over more than one row
if _match
_selectionPosition = _selection.marker.getPixelRange()
{left, width} = Editor.pixelRectForScreenRange(_selection.getScreenRange())
right = left + width
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please prefix the variables with _.

@thomaslindstrom
Copy link
Owner

Sorry for taking long. I'm going back home on Monday, so I'll push this out then.

@as-cii
Copy link
Contributor Author

as-cii commented Oct 5, 2015

No worries, I have just updated this with your suggestions. 😉

thomaslindstrom added a commit that referenced this pull request Oct 5, 2015
Use TextEditor::pixelRectForScreenRange instead of Marker::getPixelRange
@thomaslindstrom thomaslindstrom merged commit 6bcc670 into thomaslindstrom:master Oct 5, 2015
@thomaslindstrom
Copy link
Owner

Alright, this is now included in v2.0.13. Thanks, @as-cii and @philipgiuliani!

@as-cii as-cii deleted the remove-marker-getpixelrange branch October 5, 2015 12:40
@as-cii
Copy link
Contributor Author

as-cii commented Oct 5, 2015

❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants