Homec4science

Add a Javascript method to find the pixel position of a range in a textarea

Authored by epriestley <git@epriestley.com> on Aug 18 2014, 22:15.

Description

Add a Javascript method to find the pixel position of a range in a textarea

Summary:
Ref T3725. This might eventually allow us to do @username typeaheads in textareas.

Javascript!!!

Test Plan:
Dumped this into console and got a "<<<" at the caret position in Safari, Firefox and Chrome.

setInterval(function() {

var area = JX.$('comment-content');
var r = JX.TextAreaUtils.getSelectionRange(area);
var d = JX.TextAreaUtils.getPixelDimensions(area, r.start, r.end);

JX.log(d);

try {
  JX.DOM.remove(JX.$('ptr'));
} catch (_) {}

document.body.appendChild(
  JX.$N(
    'div',
    {id: "ptr", style: { position: 'absolute', left: d.start.x + 'px', top: d.start.y + 'px', zIndex: 9999, border: '2px solid red' }},
    '<<<'));
}, 1000);

Reviewers: chad, btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T3725

Differential Revision: https://secure.phabricator.com/D10280

Details

Committed
epriestley <git@epriestley.com>Aug 18 2014, 22:15
Pushed
aubortJan 31 2017, 17:16
Parents
rPH1652e07b4d97: Provide a purchase detail view in Phortune
Branches
Unknown
Tags
Unknown

Event Timeline

epriestley <git@epriestley.com> committed rPHfe042def42b0: Add a Javascript method to find the pixel position of a range in a textarea (authored by epriestley <git@epriestley.com>).Aug 18 2014, 22:15