Class zebkit.util.Position <zebkit.util>

Useful class to track a virtual cursor position in a structure that has dedicated number of lines where every line has a number of elements. The structure metric has to be described by providing an instance of zebkit.util.Position.Metric interface that discovers how many lines the structure has and how many elements every line includes.

Constructor:
zebkit.util.Position (m)

Parameters:



public <Integer> getOffsetByPoint (row, col)
public <Array> getPointByOffset (off)
protected void removed (off, size)
protected void removed (off, size)
public <Integer> seek (off)
public void seekLineTo (t, num)
public void setMetric (p)
public <Integer> setOffset (o)
public void setRowCol (r, c)

public <Integer> getOffsetByPoint (row, col)

Calculate an offset by the given line and column in the line


Parameters:
  • row <Integer>

    a line

  • col <Integer>

    a column in the line


Returns: <Integer>

an offset

public <Array> getPointByOffset (off)

Calculate a line and line column by the given offset.


Parameters:
  • off <Integer>

    an offset


Returns: <Array>

an array that contains a line as the first element and a column in the line as the second element.

protected void removed (off, size)

Special method to inform the position object that its state has to be adjusted because of the given portion of data had been inserted .


Parameters:
  • off <Integer>

    an offset the insertion has happened

  • size <Integer>

    a length of the inserted portion

protected void removed (off, size)

Special method to inform the position object that its state has to be adjusted because of the given portion of data had been removed.


Parameters:
  • off <Integer>

    an offset the removal has happened

  • size <Integer>

    a length of the removed portion

public <Integer> seek (off)

Seek virtual cursor offset with the given shift


Parameters:
  • off <Integer>

    a shift


Returns: <Integer>

an offset that has been set

public void seekLineTo (t, num)

Seek virtual cursor to the next position. How the method has to seek to the next position has to be denoted by one of the following constants:

   - **"begin"** seek cursor to the begin of the current line
   - **"end"** seek cursor to the end of the current line
   - **"up"** seek cursor one line up
   - **"down"** seek cursor one line down

If the current virtual position is not known (-1) the method always sets it to the first line, the first column in the line (offset is zero).


Parameters:
  • t <Integer>

    an action the seek has to be done

  • num <Integer>

    number of seek actions

public void setMetric (p)

Set position metric. Metric describes how many lines and elements in these line the virtual cursor can be navigated


Parameters:
public <Integer> setOffset (o)

Set the specified virtual cursor offsest


Parameters:
  • o <Integer>

    an offset, pass null to set position to indefinite state.

    • if offset is null than offset will set to -1 (undefined state)
    • if offset is less than zero than offset will be set to zero
    • if offset is greater or equal to maximal possible offset it will be set to maximal possible offset

Returns: <Integer>

an offset that has been set

public void setRowCol (r, c)

Set the virtual cursor line and the given column in the line


Parameters:
  • r <Integer>

    a line

  • c <Integer>

    a column in the line


public <Integer> currentCol

Current virtual cursor column position

public <Integer> currentLine

Current virtual cursor line position

private <Boolean> isValid

Shows if the position object is in valid state.

public <Integer> offset

Current virtual cursor offset


posChanged

Fire when a virtual cursor position has been updated

 position.on(function(src, prevOffset, prevLine, prevCol) {
     ...
 });

Parameters:
  • src <zebkit.util.Position>

    an object that triggers the event

  • prevOffest <Integer>

    a previous virtual cursor offset

  • prevLine <Integer>

    a previous virtual cursor line

  • prevCol <Integer>

    a previous virtual cursor column in the previous line