Page MenuHomePhabricator

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

Authored by epriestley on Aug 15 2014, 10:10 PM.
Tags
None
Referenced Files
F17315020: D10280.diff
Thu, Jun 26, 2:46 PM
Unknown Object (File)
Fri, Jun 20, 12:13 PM
Unknown Object (File)
Thu, Jun 19, 10:24 AM
Unknown Object (File)
Wed, Jun 18, 9:09 AM
Unknown Object (File)
May 19 2025, 8:22 AM
Unknown Object (File)
Apr 21 2025, 8:04 AM
Unknown Object (File)
Apr 14 2025, 2:26 PM
Unknown Object (File)
Apr 10 2025, 3:08 PM
Subscribers

Details

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);

Diff Detail

Repository
rP Phabricator
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

epriestley retitled this revision from to Add a Javascript method to find the pixel position of a range in a textarea.
epriestley updated this object.
epriestley edited the test plan for this revision. (Show Details)
epriestley added reviewers: btrahan, chad.
webroot/rsrc/css/core/remarkup.css
428–429

(These just merged into the rule above.)

btrahan edited edge metadata.
This revision is now accepted and ready to land.Aug 18 2014, 5:48 PM
epriestley updated this revision to Diff 24782.

Closed by commit rPfe042def42b0 (authored by @epriestley).