1.0.7 • Published 4 months ago

text-cusor-helper v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

Text Cursor Helper

This library provides fast ways to deal with the text cursor when editing in input, textarea, and div (contenteditable = true) elements:

  • Get position of the text cursor on the Oxy coordinate axis
  • Move the text cursor to the end of input fields

Installing

Using npm

  npm i text-cusor-helper

Using yarn

  yarn add text-cusor-helper

Once the package is installed, you can import using ES Modules:

import textCursorHelper from 'text-cusor-helper';

Quick Start

Get position of the text cursor

Returns X, Y coordinates for positioning of a text cursor within a given text input at a given selection point

Parameters:

OrderNameDescriptionType
1inputThe text input that need deal with text cursor inside itElement
2anchorThe element serves as a reference for coordinates calculation (The origin of Oxy coordinates)textCursorHelper.ANCHOR: ROOT DefaultPOSITIONED_PARENT: the nearest parent element having the position attribute is relative or absolute

Example:

const inputElement = document.querySelector(".comment-input")
const position = textCursorHelper.getCursorXY(
  inputElement,
  textCursorHelper.ANCHOR.POSITIONED_PARENT
);

console.log(position)
// { x: 50: y : 50 }
1.0.2

4 months ago

1.0.1

4 months ago

1.0.7

4 months ago

1.0.6

4 months ago

1.0.5

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.0

5 months ago