# Class: DocumentView

## DocumentView()

The document view.

Contains node views, that is, client-side views of server-side XML nodes. More information in NodeView.

Not yet fully documented.

## Constructor

#### new DocumentView()

Source:
  - view/DocumentView.js, line 8

### Classes

DocumentView

### Members

#### bindings :array

Get the `bindings` property of this document view: an array of Bindings currently used for the document being edited; `null` if no document is currently being edited.

##### Type:

- array

Source:
  - view/DocumentView.js, line 807

#### button2PastesText :boolean

Get/Set the `button2PastesText` property of document view: same as XMLEditor#button2PastesText.

##### Type:

- boolean

Source:
  - view/DocumentView.js, line 101

#### dot :Element

Get the `dot` property of this document view: the text node view containing `dot` if any; `null` otherwise.

##### Type:

- Element

Source:
  - view/DocumentView.js, line 907

#### dotOffset :number

Get the `dotOffset` property of this document view: the character offset of `dot` if any; -1 otherwise.

##### Type:

- number

Source:
  - view/DocumentView.js, line 918

#### mark :Element

Get the `mark` property of this document view: the text node view containing `mark` if any; `null` otherwise.

##### Type:

- Element

Source:
  - view/DocumentView.js, line 930

#### markOffset :number

Get the `markOffset` property of this document view: the character offset of `mark` if any; -1 otherwise.

##### Type:

- number

Source:
  - view/DocumentView.js, line 940

#### namespacePrefixes :array

Get the `namespacePrefixes` property of this document view: a (possibly empty) array containing namespace prefix/URI pairs; `null` if no document is currently being edited.

The default namespace (having an empty prefix), if any, is always the last pair of returned array.

##### Type:

- array

Source:
  - view/DocumentView.js, line 881

#### selected :Element

Get the `selected` property of this document view: the `selected` node view if any; `null` otherwise.

##### Type:

- Element

Source:
  - view/DocumentView.js, line 950

#### selected2 :Element

Get the `selected2` property of this document view: the `selected2` node view if any; `null` otherwise.

##### Type:

- Element

Source:
  - view/DocumentView.js, line 960

#### viewContainer :Element

Get the `viewContainer` property of this document view: the descendant element of this document view which contains all the node views.

##### Type:

- Element

Source:
  - view/DocumentView.js, line 171

#### xmlEditor :XMLEditor

Get/Set the `xmlEditor` property of document view: the XMLEditor containing this document view.

##### Type:

- XMLEditor

Source:
  - view/DocumentView.js, line 76

### Methods

#### canEdit()

Tests wether this document view is editable. Returns `false` either because no document is currently opened or opened document is marked read-only or the peer document view configured as not editable.

Source:
  - view/DocumentView.js, line 1479

#### ensureDotIsInside()

If needed to, adds `dotdotOffset`marksview.

Does nothing if this is not possible for specified view.

Source:
  - view/DocumentView.js, line 1064

#### executeCommand(mode, commandName, commandParams, eventopt) → {Promise}

Tests wether specified command can be executed or actually executes specified command, whether this command is remote or local.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`mode` | number |  |  | specifies how this command is to be executed.
`commandName` | string |  |  | the command name.
`commandParams` | string |  |  | parameterizes the command. May be `null`.
`event` | UIEvent | <optional> | null | the keyboard or event which triggered this command. May be `null`.

Source:
  - view/DocumentView.js, line 1512
See:
  - Command#execute

##### Returns:

A Promise containing:

- If `mode` is `EXECUTE_TEST`, `true` if the command can be executed, `false` otherwise.
- In the other modes, a CommandResult.
- `null` if this command has not been executed or if an error of any kind occurs.

Type
  Promise

#### getAppEventBinding()

Returns the Binding which associates the application event having specified name (e.g. `"resize-image"`, `"rescale-image"`) to a command. Returns `null` if no document is currently being edited or if there is no such binding.

Source:
  - view/DocumentView.js, line 819

#### getBindingForCommand()

Returns the Binding used to invoke specified command. Returns `null` if no document is currently being edited or if there is no such binding.

Source:
  - view/DocumentView.js, line 844

#### getCommand()

Return the instance of command having specified name.

If specified command is not a local command, a new instance of RemoteCommand is returned.

Source:
  - view/DocumentView.js, line 1522

#### getCommandState()

A cover for XMLEditor#getCommandState.

Source:
  - view/DocumentView.js, line 896

#### getSelectedText()

Returns text selection if any; `null` otherwise.

Source:
  - view/DocumentView.js, line 977

#### hasNodeSelection()

Tests whether there is a node selection.

Source:
  - view/DocumentView.js, line 1029

#### hasTextSelection()

Tests whether there is a text selection.

Source:
  - view/DocumentView.js, line 967

#### makeSelectionVisible(expandopt)

Scrolls the selection, if any, to center it in this document view.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`expand` | boolean | <optional> | false | expand - if `true`, when needed to, expand the views of the ancestors of the nodes comprising the selection to really make the selection visible.

Source:
  - view/DocumentView.js, line 1020

#### pickTextualView(mouseEvent, pickedTextopt) → {array}

Find the text node view and the text offset corresponding to specified coordinates.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`mouseEvent` | MouseEvent |  |  | specifies the coordinates where the search begins.
`pickedText` | array | <optional> | null | if not `null`, the result is stored there.

Source:
  - view/DocumentView.js, line 1120

##### Returns:

An array containing two items. First item is a text node view or `null` (if the search has failed). Second item is a text offset or -1 (if the search has failed). The returned array is `pickedText` if specified and a newly created array otherwise.

Type
  array

#### requestFocus()

Ensures that this document view has the keyboard focus and that the caret is blinking (if the dot mark exists).

Source:
  - view/DocumentView.js, line 1007

#### selectionContains()

Tests whether specified mouse click is contained in text or node selection (if any).

Source:
  - view/DocumentView.js, line 1304

#### selectNode(view, showopt) → {Promise}

Select the node having specified view.

Automatically invokes DocumentView#ensureDotIsInside.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`view` |  |  |  | specifies the node to be selected by its view.
`show` | boolean | <optional> | false | show - if `true`, when needed to, expand the views of the ancestors of specified node to really make the node visible.

Source:
  - view/DocumentView.js, line 1045

##### Returns:

A Promise containing `true` if the selection has been successfully changed; `false` otherwise (even when an error occurs).

Type
  Promise

#### selectNodeRange(view1, view2) → {Promise}

Select the node range specified using the view of first node of the range and the view of last node of the range.

Specified views must have a common parent view to make sure that corresponding nodes are siblings.

Automatically invokes DocumentView#ensureDotIsInside.

##### Parameters:

Name | Type | Description
--- | --- | ---
`view1` |  | specifies the first node of the range.
`view2` |  | specifies the last node of the range.

Source:
  - view/DocumentView.js, line 1089

##### Returns:

A Promise containing `true` if the selection has been successfully changed; `false` otherwise (even when an error occurs).

Type
  Promise

#### sendExecuteCommand(mode, commandName, commandParams) → {Promise}

Tests wether specified remote command can be executed or actually executes specified remote command.

##### Parameters:

Name | Type | Description
--- | --- | ---
`mode` | number | specifies how this command is to be executed.
`commandName` | string | the command name.
`commandParams` | string | parameterizes the command. May be `null`.

Source:
  - view/DocumentView.js, line 1549
See:
  - RemoteCommand

##### Returns:

A Promise containing:

- If `mode` is `EXECUTE_TEST`, `true` if the command can be executed, `false` otherwise.
- In the other modes, a CommandResult.
- `null` if this command has not been executed (for example, an unknown command) or if an error of any kind occurs.

Type
  Promise

#### sendSetClipboard(copied) → {Promise}

Copy a string in to clipboard on the server side.

##### Parameters:

Name | Type | Description
--- | --- | ---
`copied` | string | String to be copied.

Source:
  - view/DocumentView.js, line 1389

##### Returns:

A Promise containing `true` if the server-side clipboard has been successfully updated; `false` otherwise (even when an error occurs).

Type
  Promise

#### sendSetMarks(marks) → {Promise}

Change node marks on the server side.

##### Parameters:

Name | Type | Description
--- | --- | ---
`marks` | object | an object containing one or more of the following keys: `dot`: UID or "", dotOffset: integer, `mark`: UID or "", markOffset: integer, `selected`: UID or "", `selected2`: UID or "". `reason`: "dragging", "showing" or `null`. "dragging": if a quick sequence of change marks requests is being sent to the server. "showing": if the goal is to show the selection to the user, in which case, the MarkManager may have to expand some collapsed node views after receiving the marks changed event. Use "" to clear a mark, UID to set it. Value `null` is ignored.

Source:
  - view/DocumentView.js, line 1339

##### Returns:

A Promise containing `true` if specified marks were successfully changed; `false` otherwise (even when an error occurs).

Note that DocumentMarksChangedEvents and EditingContextChangedEvents are received before this Promise is fulfilled.

Type
  Promise

#### sendSetPrimarySelection(copied) → {Promise}

Copy a string as the primary selection on the server side.

##### Parameters:

Name | Type | Description
--- | --- | ---
`copied` | string | String to be copied.

Source:
  - view/DocumentView.js, line 1444

##### Returns:

A Promise containing `true` if the server-side primary selection has been successfully updated; `false` otherwise (even when an error occurs).

Type
  Promise

#### showStatus()

Equivalent to this.xmlEditor.showStatus(text, autoErase).

Source:
  - view/DocumentView.js, line 889

#### sync() → {Promise}

Update server-side text node content and dot to match the state of currently used (focused) contenteditable.

Source:
  - view/DocumentView.js, line 1597

##### Returns:

A Promise containing `true` if sync was successful; `false` otherwise (an internal error which should not happen).

Type
  Promise

#### updatePrimarySelection()

When DocumentView#button2PastesText is `true`, update the (emulated) primary selection by copying selected text to it.

Source:
  - view/DocumentView.js, line 1422