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)
Sat, Dec 14, 1:02 AM
Unknown Object (File)
Wed, Dec 11, 1:19 AM
Unknown Object (File)
Nov 26 2024, 8:55 PM
Unknown Object (File)
Nov 24 2024, 4:52 PM
Unknown Object (File)
Nov 22 2024, 5:41 PM
Unknown Object (File)
Nov 22 2024, 8:00 AM
Unknown Object (File)
Nov 22 2024, 7:45 AM
Unknown Object (File)
Nov 18 2024, 12:43 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).