File codemirror.js
has 7686 lines of code (exceeds 250 allowed). Consider refactoring. Open
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// This is CodeMirror (http://codemirror.net), a code editor
// implemented in JavaScript on top of the browser's DOM.
- Create a ticketCreate a ticket
Function addEditorMethods
has 378 lines of code (exceeds 25 allowed). Consider refactoring. Open
function addEditorMethods(CodeMirror) {
var optionHandlers = CodeMirror.optionHandlers
var helpers = CodeMirror.helpers = {}
- Create a ticketCreate a ticket
Function defineOptions
has 116 lines of code (exceeds 25 allowed). Consider refactoring. Open
function defineOptions(CodeMirror) {
var optionHandlers = CodeMirror.optionHandlers
function option(name, deflt, handle, notOnInit) {
CodeMirror.defaults[name] = deflt
- Create a ticketCreate a ticket
Function leftButtonSelect
has 114 lines of code (exceeds 25 allowed). Consider refactoring. Open
function leftButtonSelect(cm, event, start, behavior) {
var display = cm.display, doc = cm.doc
e_preventDefault(event)
var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges
- Create a ticketCreate a ticket
Function bidiOrdering
has 100 lines of code (exceeds 25 allowed). Consider refactoring. Open
var bidiOrdering = (function() {
// Character types for codepoints 0 to 0xff
var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN"
// Character types for codepoints 0x600 to 0x6f9
var arabicTypes = "nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111"
- Create a ticketCreate a ticket
Function registerEventHandlers
has 89 lines of code (exceeds 25 allowed). Consider refactoring. Open
function registerEventHandlers(cm) {
var d = cm.display
on(d.scroller, "mousedown", operation(cm, onMouseDown))
// Older IE's will not fire a second mousedown for a double click
if (ie && ie_version < 11)
- Create a ticketCreate a ticket
Function drawSelectionRange
has 81 lines of code (exceeds 25 allowed). Consider refactoring. Open
function drawSelectionRange(cm, range, output) {
var display = cm.display, doc = cm.doc
var fragment = document.createDocumentFragment()
var padding = paddingH(cm.display), leftSide = padding.left
var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right
- Create a ticketCreate a ticket
Function init
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
ContentEditableInput.prototype.init = function (display) {
var this$1 = this;
var input = this, cm = input.cm
var div = input.div = display.lineDiv
- Create a ticketCreate a ticket
Function onContextMenu
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
TextareaInput.prototype.onContextMenu = function (e) {
var input = this, cm = input.cm, display = cm.display, te = input.textarea
var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop
if (!pos || presto) { return } // Opera is difficult.
- Create a ticketCreate a ticket
Function insertLineContent
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
function insertLineContent(line, builder, styles) {
var spans = line.markedSpans, allText = line.text, at = 0
if (!spans) {
for (var i$1 = 1; i$1 < styles.length; i$1+=2)
{ builder.addToken(builder, allText.slice(at, at = styles[i$1]), interpretTokenStyle(styles[i$1+1], builder.cm.options)) }
- Create a ticketCreate a ticket
Function pollContent
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
ContentEditableInput.prototype.pollContent = function () {
if (this.readDOMTimeout != null) {
clearTimeout(this.readDOMTimeout)
this.readDOMTimeout = null
}
- Create a ticketCreate a ticket
Function buildToken
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
function buildToken(builder, text, style, startStyle, endStyle, title, css) {
if (!text) { return }
var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text
var special = builder.cm.state.specialChars, mustWrap = false
var content
- Create a ticketCreate a ticket
Function init
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
TextareaInput.prototype.init = function (display) {
var this$1 = this;
var input = this, cm = this.cm
this.createField(display)
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (!(span.to != null && lineNo == from.line && from.ch >= span.to ||
span.from == null && lineNo != from.line ||
span.from != null && lineNo == to.line && span.from >= to.ch) &&
(!filter || filter(span.marker)))
{ found.push(span.marker.parent || span.marker) }
- Create a ticketCreate a ticket
Function regChange
has 56 lines of code (exceeds 25 allowed). Consider refactoring. Open
function regChange(cm, from, to, lendiff) {
if (from == null) { from = cm.doc.first }
if (to == null) { to = cm.doc.first + cm.doc.size }
if (!lendiff) { lendiff = 0 }
- Create a ticketCreate a ticket
Function makeChangeFromHistory
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
function makeChangeFromHistory(doc, type, allowSelectionOnly) {
var suppress = doc.cm && doc.cm.state.suppressEdits
if (suppress && !allowSelectionOnly) { return }
var hist = doc.history, event, selAfter = doc.sel
- Create a ticketCreate a ticket
Function markText
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
function markText(doc, from, to, options, type) {
// Shared markers (across linked documents) are handled separately
// (markTextShared will call out to this again, once per
// document).
if (options && options.shared) { return markTextShared(doc, from, to, options, type) }
- Create a ticketCreate a ticket
Function onDrop
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
function onDrop(e) {
var cm = this
clearDragCursor(cm)
if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
{ return }
- Create a ticketCreate a ticket
Function findPosH
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
function findPosH(doc, pos, dir, unit, visually) {
var oldPos = pos
var origDir = dir
var lineObj = getLine(doc, pos.line)
function findNextLine() {
- Create a ticketCreate a ticket
Function CodeMirror
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
function CodeMirror(place, options) {
var this$1 = this;
if (!(this instanceof CodeMirror)) { return new CodeMirror(place, options) }
- Create a ticketCreate a ticket
Function Display
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
function Display(place, doc, input) {
var d = this
this.input = input
// Covers bottom-right square when both scrollbars are present.
- Create a ticketCreate a ticket
Function moveVisually
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
function moveVisually(cm, line, start, dir) {
var bidi = getOrder(line, cm.doc.direction)
if (!bidi) { return moveLogically(line, start, dir) }
if (start.ch >= line.text.length) {
start.ch = line.text.length
- Create a ticketCreate a ticket
Function onScrollWheel
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
function onScrollWheel(cm, e) {
var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y
var display = cm.display, scroll = display.scroller
// Quit if there's nothing to scroll here
- Create a ticketCreate a ticket
Function drawForLine
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
function drawForLine(line, fromArg, toArg) {
var lineObj = getLine(doc, line)
var lineLen = lineObj.text.length
var start, end
function coords(ch, bias) {
- Create a ticketCreate a ticket
Function indentLine
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
function indentLine(cm, n, how, aggressive) {
var doc = cm.doc, state
if (how == null) { how = "add" }
if (how == "smart") {
// Fall back to "prev" when the mode doesn't have an indentation
- Create a ticketCreate a ticket
Function updateDisplayIfNeeded
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
function updateDisplayIfNeeded(cm, update) {
var display = cm.display, doc = cm.doc
if (update.editorIsHidden) {
resetView(cm)
- Create a ticketCreate a ticket
Function locateNodeInLineView
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
function locateNodeInLineView(lineView, node, offset) {
var wrapper = lineView.text.firstChild, bad = false
if (!node || !contains(wrapper, node)) { return badPos(Pos(lineNo(lineView.line), 0), true) }
if (node == wrapper) {
bad = true
- Create a ticketCreate a ticket
Function stretchSpansOverChange
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
function stretchSpansOverChange(doc, change) {
if (change.full) { return null }
var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans
var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans
if (!oldFirst && !oldLast) { return null }
- Create a ticketCreate a ticket
Function makeChangeSingleDocInEditor
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
function makeChangeSingleDocInEditor(cm, change, spans) {
var doc = cm.doc, display = cm.display, from = change.from, to = change.to
var recomputeMaxLength = false, checkWidthStart = from.line
if (!cm.options.lineWrapping) {
- Create a ticketCreate a ticket
Function fromTextArea
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
function fromTextArea(textarea, options) {
options = options ? copyObj(options) : {}
options.value = textarea.value
if (!options.tabindex && textarea.tabIndex)
{ options.tabindex = textarea.tabIndex }
- Create a ticketCreate a ticket
Function measureCharInner
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
function measureCharInner(cm, prepared, ch, bias) {
var place = nodeAndOffsetInLineMap(prepared.map, ch, bias)
var node = place.node, start = place.start, end = place.end, collapse = place.collapse
var rect
- Create a ticketCreate a ticket
Function domTextBetween
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
function domTextBetween(cm, from, to, fromLine, toLine) {
var text = "", closing = false, lineSep = cm.doc.lineSeparator()
function recognizeMarker(id) { return function (marker) { return marker.id == id; } }
function close() {
if (closing) {
- Create a ticketCreate a ticket
Function showPrimarySelection
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
ContentEditableInput.prototype.showPrimarySelection = function () {
var sel = window.getSelection(), cm = this.cm, prim = cm.doc.sel.primary()
var from = prim.from(), to = prim.to()
if (cm.display.viewTo == cm.display.viewFrom || from.line >= cm.display.viewTo || to.line < cm.display.viewFrom) {
- Create a ticketCreate a ticket
Function updateDoc
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
function updateDoc(doc, change, markedSpans, estimateHeight) {
function spansFor(n) {return markedSpans ? markedSpans[n] : null}
function update(line, text, spans) {
updateLine(line, text, spans, estimateHeight)
signalLater(line, "change", line, change)
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (ltr) {
topLeft = docLTR && openStart && first ? leftSide : fromPos.left
topRight = docLTR ? rightSide : wrapX(from, dir, "before")
botLeft = docLTR ? leftSide : wrapX(to, dir, "after")
botRight = docLTR && openEnd && last ? rightSide : toPos.right
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() &&
repeat == "single" && (contained = sel.contains(pos)) > -1 &&
(cmp((contained = sel.ranges[contained]).from(), pos) < 0 || pos.xRel > 0) &&
(cmp(contained.to(), pos) > 0 || pos.xRel < 0))
{ leftButtonStartDrag(cm, event, pos, behavior) }
- Create a ticketCreate a ticket
Function addLegacyProps
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
function addLegacyProps(CodeMirror) {
CodeMirror.off = off
CodeMirror.on = on
CodeMirror.wheelEventPixels = wheelEventPixels
CodeMirror.Doc = Doc
- Create a ticketCreate a ticket
Function applyTextInput
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
function applyTextInput(cm, inserted, deleted, sel, origin) {
var doc = cm.doc
cm.display.shift = false
if (!sel) { sel = doc.sel }
- Create a ticketCreate a ticket
Function coordsCharInner
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
function coordsCharInner(cm, lineObj, lineNo, x, y) {
// Move y into line-local coordinate space
y -= heightAtLine(lineObj)
var preparedMeasure = prepareMeasureForLine(cm, lineObj)
// When directly calling `measureCharPrepared`, we have to adjust
- Create a ticketCreate a ticket
Function buildLineContent
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
function buildLineContent(cm, lineView) {
// The padding-right forces the element to have a 'border', which
// is needed on Webkit to be able to get line-level bounding
// rectangles for it (in measureChar).
var content = eltP("span", null, null, webkit ? "padding-right: .1px" : null)
- Create a ticketCreate a ticket
Function clear
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
TextMarker.prototype.clear = function () {
var this$1 = this;
if (this.explicitlyCleared) { return }
var cm = this.doc.cm, withOp = cm && !cm.curOp
- Create a ticketCreate a ticket
Function highlightWorker
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
function highlightWorker(cm) {
var doc = cm.doc
if (doc.highlightFrontier >= cm.display.viewTo) { return }
var end = +new Date + cm.options.workTime
var context = getContextBefore(cm, doc.highlightFrontier)
- Create a ticketCreate a ticket
Function updateLineGutter
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
function updateLineGutter(cm, lineView, lineN, dims) {
if (lineView.gutter) {
lineView.node.removeChild(lineView.gutter)
lineView.gutter = null
}
- Create a ticketCreate a ticket
Function onCopyCut
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
function onCopyCut(e) {
if (signalDOMEvent(cm, e)) { return }
if (cm.somethingSelected()) {
setLastCopied({lineWise: false, text: cm.getSelections()})
if (e.type == "cut") { cm.replaceSelection("", null, "cut") }
- Create a ticketCreate a ticket
Function extendTo
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
function extendTo(pos) {
if (cmp(lastPos, pos) == 0) { return }
lastPos = pos
if (behavior.unit == "rectangle") {
- Create a ticketCreate a ticket
Function patchDisplay
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
function patchDisplay(cm, updateNumbersFrom, dims) {
var display = cm.display, lineNumbers = cm.options.lineNumbers
var container = display.lineDiv, cur = container.firstChild
function rm(node) {
- Create a ticketCreate a ticket
Function highlightLine
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
function highlightLine(cm, line, context, forceToEnd) {
// A styles array always starts with a number identifying the
// mode/overlays that it is based on (for easy invalidation).
var st = [cm.state.modeGen], lineClasses = {}
// Compute the base array of styles
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (this.contextMenuPending || !cm.state.focused ||
(hasSelection(input) && !prevInput && !this.composing) ||
cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq)
{ return false }
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to &&
(sp.to == null || sp.to != span.from) &&
(sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
lineIsHiddenInner(doc, line, sp)) { return true }
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (context.line >= cm.display.viewFrom) { // Visible
var oldStyles = line.styles
var resetState = line.text.length > cm.options.maxHighlightLength ? copyState(doc.mode, context.state) : null
var highlighted = highlightLine(cm, line, context, true)
if (resetState) { context.state = resetState }
- Create a ticketCreate a ticket
Function addChangeToHistory
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
function addChangeToHistory(doc, change, selAfter, opId) {
var hist = doc.history
hist.undone.length = 0
var time = +new Date, cur
var last
- Create a ticketCreate a ticket
Function runMode
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) {
var flattenSpans = mode.flattenSpans
if (flattenSpans == null) { flattenSpans = cm.options.flattenSpans }
var curStart = 0, curStyle = null
var stream = new StringStream(text, cm.options.tabSize, context), style
- Create a ticketCreate a ticket
Function nodeAndOffsetInLineMap
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
function nodeAndOffsetInLineMap(map, ch, bias) {
var node, start, end, collapse, mStart, mEnd
// First, search the line map for the text node corresponding to,
// or closest to, the target character.
for (var i = 0; i < map.length; i += 3) {
- Create a ticketCreate a ticket
Function leftButtonStartDrag
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
function leftButtonStartDrag(cm, event, pos, behavior) {
var display = cm.display, moved = false
var dragEnd = operation(cm, function (e) {
if (webkit) { display.scroller.draggable = false }
cm.state.draggingText = false
- Create a ticketCreate a ticket
Function poll
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
TextareaInput.prototype.poll = function () {
var this$1 = this;
var cm = this.cm, input = this.textarea, prevInput = this.prevInput
// Since this is called a *lot*, try to bail out as cheaply as
- Create a ticketCreate a ticket
Function addWidget
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
addWidget: function(pos, node, scroll, vert, horiz) {
var display = this.display
pos = cursorCoords(this, clipPos(this.doc, pos))
var top = pos.bottom, left = pos.left
node.style.position = "absolute"
- Create a ticketCreate a ticket
Function update
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
NativeScrollbars.prototype.update = function (measure) {
var needsH = measure.scrollWidth > measure.clientWidth + 1
var needsV = measure.scrollHeight > measure.clientHeight + 1
var sWidth = measure.nativeBarWidth
- Create a ticketCreate a ticket
Function scrollPosIntoView
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
function scrollPosIntoView(cm, pos, end, margin) {
if (margin == null) { margin = 0 }
var rect
if (!cm.options.lineWrapping && pos == end) {
// Set pos and end to the cursor positions around the character pos sticks to
- Create a ticketCreate a ticket
Function onMouseDown
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
function onMouseDown(e) {
var cm = this, display = cm.display
if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) { return }
display.input.ensurePolled()
display.shift = e.shiftKey
- Create a ticketCreate a ticket
Function skipAtomicInner
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
var line = getLine(doc, pos.line)
if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
var sp = line.markedSpans[i], m = sp.marker
if ((sp.from == null || (m.inclusiveLeft ? sp.from <= pos.ch : sp.from < pos.ch)) &&
- Create a ticketCreate a ticket
Function loop
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
var loop = function ( o ) {
context.baseTokens = st
var overlay = cm.state.overlays[o], i = 1, at = 0
context.state = true
runMode(cm, line.text, overlay.mode, context, function (end, style) {
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if ((hist.lastOp == opId ||
hist.lastOrigin == change.origin && change.origin &&
((change.origin.charAt(0) == "+" && hist.lastModTime > time - (doc.cm ? doc.cm.options.historyEventDelay : 500)) ||
change.origin.charAt(0) == "*")) &&
(cur = lastChangeEvent(hist, hist.lastOp == opId))) {
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh)
;(nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh,
span.to == null ? null : span.to - endCh))
}
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (!update.force &&
update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
(display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
display.renderedView == display.view && countDirtyView(cm) == 0)
{ return false }
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh)
;(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to))
}
- Create a ticketCreate a ticket
Function runMode
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) {
- Create a ticketCreate a ticket
Function buildToken
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
function buildToken(builder, text, style, startStyle, endStyle, title, css) {
- Create a ticketCreate a ticket
Function coordsBidiPartWrapped
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
function coordsBidiPartWrapped(cm, lineObj, _lineNo, preparedMeasure, order, x, y) {
- Create a ticketCreate a ticket
Function coordsBidiPart
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
function coordsBidiPart(cm, lineObj, lineNo, preparedMeasure, order, x, y) {
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (pos < j$2) { order.splice(at, 0, new BidiSpan(1, pos, j$2)) }
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
{ if (oldCur[k].marker == span.marker) { continue spans } }
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
{ collapsed = sp }
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
{ if (endStyles[j$1 + 1] == nextChange) { spanEndStyle += " " + endStyles[j$1] } } }
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (m.className) { spanStyle += " " + m.className }
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (m.title && !title) { title = m.title }
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (cutTop && cutBot) {
display.view = display.view.slice(0, cutTop.index)
.concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
.concat(display.view.slice(cutBot.index))
display.viewTo += lendiff
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (m.css) { css = (css ? css + ";" : "") + m.css }
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
} else if (sp.from > pos && nextChange > sp.from) {
nextChange = sp.from
}
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (m.endStyle && sp.to == nextChange) { (endStyles || (endStyles = [])).push(m.endStyle, sp.to) }
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
for (++j$2; j$2 < i$7 && countsAsNum.test(types[j$2]); ++j$2) {}
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (sp.to != null && sp.to != pos && nextChange > sp.to) {
nextChange = sp.to
spanEndStyle = ""
}
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (m.startStyle && sp.from == pos) { spanStartStyle += " " + m.startStyle }
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (sameLine) { (first || (first = [])).push(span$1) }
- Create a ticketCreate a ticket
Function cursorCoords
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (cut$1) {
display.view = display.view.slice(0, cut$1.index)
display.viewTo = cut$1.lineN
} else {
resetView(cm)
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (newGroup) { for (var prop in change) { if (m = prop.match(/^spans_(\d+)$/)) {
if (indexOf(newGroup, Number(m[1])) > -1) {
lst(newChanges)[prop] = change[prop]
delete change[prop]
}
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (dir < 0 ? m.inclusiveRight : m.inclusiveLeft)
{ near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null) }
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (m.explicitlyCleared) {
if (!line.markedSpans) { break }
else {--i; continue}
}
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0))
{ return skipAtomicInner(doc, near, pos, dir, mayClear) }
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) ||
fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0))
{ return true }
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad &&
cmp(minPos(curAnchor, curFocus), from) == 0 &&
cmp(maxPos(curAnchor, curFocus), to) == 0)
{ return }
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
(display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
{ return false }
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (display.wheelStartX == null) {
display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop
display.wheelDX = dx; display.wheelDY = dy
setTimeout(function () {
if (display.wheelStartX == null) { return }
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (opId == hist.lastSelOp ||
(origin && hist.lastSelOrigin == origin &&
(hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin ||
selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))))
{ hist.done[hist.done.length - 1] = sel }
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) { return }
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
} else if (unit == "word" || unit == "group") {
var sawType = null, group = unit == "group"
var helper = doc.cm && doc.cm.getHelper(pos, "wordChars")
for (var first = true;; first = false) {
if (dir < 0 && !moveOnce(!first)) { break }
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (style || startStyle || endStyle || mustWrap || css) {
var fullStyle = style || ""
if (startStyle) { fullStyle += startStyle }
if (endStyle) { fullStyle += endStyle }
var token = elt("span", [content], fullStyle, css)
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
var rSpan = node.parentNode.getClientRects()[0]
if (rSpan)
{ rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom} }
else
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
} else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {
if (sp.to != null && sp.to != pos && nextChange > sp.to) {
nextChange = sp.to
spanEndStyle = ""
}
- Create a ticketCreate a ticket
Function insertLineWidgetsFor
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
- Create a ticketCreate a ticket
Function charCoords
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function charCoords(cm, pos, context, lineObj, bias) {
- Create a ticketCreate a ticket
Function skipAtomic
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function skipAtomic(doc, pos, oldPos, bias, mayClear) {
- Create a ticketCreate a ticket
Function addWidget
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
addWidget: function(pos, node, scroll, vert, horiz) {
- Create a ticketCreate a ticket
Function extendSelection
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function extendSelection(doc, head, other, options, extend) {
- Create a ticketCreate a ticket
Function markText
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function markText(doc, from, to, options, type) {
- Create a ticketCreate a ticket
Function applyTextInput
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function applyTextInput(cm, inserted, deleted, sel, origin) {
- Create a ticketCreate a ticket
Function intoCoordSystem
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function intoCoordSystem(cm, lineObj, rect, context, includeWidgets) {
- Create a ticketCreate a ticket
Function PosWithInfo
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function PosWithInfo(line, ch, sticky, outside, xRel) {
- Create a ticketCreate a ticket
Function Doc
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
var Doc = function(text, mode, firstLine, lineSep, direction) {
- Create a ticketCreate a ticket
Function handleMappedButton
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function handleMappedButton(cm, button, pos, repeat, event) {
- Create a ticketCreate a ticket
Function conflictingCollapsedRange
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function conflictingCollapsedRange(doc, lineNo, from, to, marker) {
- Create a ticketCreate a ticket
Function markTextShared
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function markTextShared(doc, from, to, options, type) {
- Create a ticketCreate a ticket
Function findPosH
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function findPosH(doc, pos, dir, unit, visually) {
- Create a ticketCreate a ticket
Function measureCharPrepared
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
- Create a ticketCreate a ticket
Function endOfLine
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function endOfLine(visually, cm, lineObj, lineNo, dir) {
- Create a ticketCreate a ticket
Function domTextBetween
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function domTextBetween(cm, from, to, fromLine, toLine) {
- Create a ticketCreate a ticket
Function coordsCharInner
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function coordsCharInner(cm, lineObj, lineNo, x, y) {
- Create a ticketCreate a ticket
Function replaceRange
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function replaceRange(doc, code, from, to, origin) {
- Create a ticketCreate a ticket
Function countColumn
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function countColumn(string, end, tabSize, startIndex, startValue) {
- Create a ticketCreate a ticket
Function skipAtomicInner
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (result) { return result }
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return true
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
else if (0x2000 <= code && code <= 0x200b) { return "w" }
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (res) { return res }
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
{ return badPos(Pos(found.line, found.ch + dist$1), bad) }
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return anchor.ch == ch && anchor.sticky == sticky ? range : new Range(new Pos(anchor.line, ch, sticky), head)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if ( returned ) return returned.v;
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
else if (code == 0x200c) { return "b" }
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return null
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
else { return "L" }
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return new Pos(pos.line, pos.ch + dir)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (handleCharBinding(cm, e, ch)) { return }
- Create a ticketCreate a ticket
Identical blocks of code found in 2 locations. Consider refactoring. Open
(function (global, factory) {
global.CodeMirror = factory();
}(this, (function () { 'use strict';
// Kludges for bugs and behavior differences that can't be feature
- Read upRead up
- Create a ticketCreate a ticket
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 121952.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76