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
Unknown Object (File)
Wed, Mar 20, 4:42 PM
Unknown Object (File)
Wed, Mar 20, 4:23 PM
Unknown Object (File)
Wed, Mar 20, 3:26 PM
Unknown Object (File)
Wed, Mar 20, 2:23 PM
Unknown Object (File)
Sun, Mar 17, 8:43 PM
Unknown Object (File)
Sun, Mar 10, 6:40 AM
Unknown Object (File)
Feb 14 2024, 4:58 PM
Unknown Object (File)
Feb 12 2024, 5:40 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).