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)
Mon, Nov 18, 12:43 PM
Unknown Object (File)
Wed, Nov 13, 4:39 PM
Unknown Object (File)
Sat, Nov 9, 11:55 PM
Unknown Object (File)
Wed, Nov 6, 9:55 AM
Unknown Object (File)
Fri, Nov 1, 8:27 PM
Unknown Object (File)
Oct 15 2024, 6:52 AM
Unknown Object (File)
Oct 2 2024, 10:51 AM
Unknown Object (File)
Sep 27 2024, 9:30 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
Branch
txmetrics
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 2251
Build 2255: [Placeholder Plan] Wait for 30 Seconds

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