Prototype for TextDocument objects
To create a TextDocument do this:
var parameters = new Document.Parameters ( );
parameters.document_type = "texts";
var doc = new Document (parameters, "view");
none. Use Document constructor.
none.
ECMerge 2.1
TextDocument objects are the documents which do text
comparisons and edition. They provide ways to modify text and
give information about loaded comparisons and files.
When the graphical user interface is present, they allow
you to alter current state of editable views and resolve
conflicts. When no view is opened on a text document, only
read-only operations are available, these operations let you
study the files, their comparison and produce an output by
yourself.
Property | Description |
conflicts | Array of TextDocument.Conflict. Collection of the conflicts. |
content | Array of TextDocument.Content. Read-Only. Collection of the contents loaded from the data sources |
information | See description in Document object. |
Property | Description |
syntax_colouring_language | String. Read-only. Indicates which language is actually used to colour the current text. Use the option " typed.texts.display.language" in the OptionsSet to force a particular language. |
Check that a document is a text document, and displays the number of conflicts
if (doc instanceof TextDocument)
alert ("document contains "+
doc.conflicts.length + "conflict(s)");
TextDocument.Content object, TextDocument.Conflict object
![]()
function transaction ( f )
f. Function. f is executed within an edition transaction.
TextDocument object.
ECMerge 2.1
This function is used when you want to call many times "set_text" on a TextDocument.Content or solve many conflicts (through resolution macros) and have all the commands undone at once.
Appends many times a text to the current view:
function append_text (content, text)
{
content.set_text (
new
TextDocument.Selection(content,
LinearRange(content.length, 0) ),
text);
}
var doc = current_frame.coordinator.document;
var updated_side =
doc.parameters.gui_type.substring(0,5) == 'merge' ? 'result'
: 'left';
var content = doc.content[updated_side];
var view = current_frame.coordinator.current_view;
doc.transaction (function() {
for (var i=0; i<1000; ++i)
append_text
(content, "hello world for "+ i +"th time!\n");
} );
TextDocument object, TextDocument.Content.set_text method.
function differences ( couple )
returns an Array of
TextDocument.Difference
object.
couple. Side Couple string. Couple for which the differences are requested. In 2-way, only "left-right" is legal.
TextDocument object.
ECMerge 2.1
Returns a Array of differences describing the left side in the given couple was modified with respect to the other side of the couple.
Displays a message box telling whether the two sides are identical or not:
var doc = current_frame.coordinator.document;
alert ( "Left and right sides are "+ (doc.differences
("left-right").length == 0 ? "identical" : "different")
);
TextDocument object, TextDocument.Difference object