Skip to content

Commit

Permalink
Factor view constructor into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Nov 29, 2012
1 parent 0c98afb commit 5dcaaf1
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions lib/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,7 @@ window.CodeMirror = (function() {
updateGutters(this);
if (options.autofocus) focusInput(this);

var doc = new BranchChunk([new LeafChunk([makeLine("", null, textHeight(display))])]);
// The selection. These are always maintained to point at valid
// positions.
var selPos = {line: 0, ch: 0};
this.view = {
doc: doc,
// frontier is the point up to which the content has been parsed,
frontier: 0, highlight: new Delayed(),
sel: {from: selPos, to: selPos, head: selPos, anchor: selPos, shift: false, extend: false},
scrollTop: 0, scrollLeft: 0,
overwrite: false, focused: false,
// Tracks the maximum line length so that
// the horizontal scrollbar can be kept
// static when scrolling.
maxLine: getLine(doc, 0),
maxLineLength: 0,
maxLineChanged: false,
suppressEdits: false,
goalColumn: null,
cantEdit: false
};
this.view = makeView(new BranchChunk([new LeafChunk([makeLine("", null, textHeight(display))])]));
this.nextOpId = 0;
loadMode(this);
themeChanged(this);
Expand Down Expand Up @@ -179,6 +159,29 @@ window.CodeMirror = (function() {
return d;
}

// VIEW CONSTRUCTOR

function makeView(doc) {
var selPos = {line: 0, ch: 0};
return {
doc: doc,
// frontier is the point up to which the content has been parsed,
frontier: 0, highlight: new Delayed(),
sel: {from: selPos, to: selPos, head: selPos, anchor: selPos, shift: false, extend: false},
scrollTop: 0, scrollLeft: 0,
overwrite: false, focused: false,
// Tracks the maximum line length so that
// the horizontal scrollbar can be kept
// static when scrolling.
maxLine: getLine(doc, 0),
maxLineLength: 0,
maxLineChanged: false,
suppressEdits: false,
goalColumn: null,
cantEdit: false
};
}

// STATE UPDATES

// Used to get the editor into a consistent state again when options change.
Expand Down

0 comments on commit 5dcaaf1

Please sign in to comment.