Skip to content

Commit

Permalink
Notice when lines are sticking out of the width of the editor
Browse files Browse the repository at this point in the history
Issue #5639
  • Loading branch information
marijnh committed Nov 20, 2018
1 parent 5c51f54 commit 51a3704
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/display/update_lines.js
@@ -1,6 +1,6 @@
import { heightAtLine } from "../line/spans.js"
import { getLine, lineAtHeight, updateLineHeight } from "../line/utils_line.js"
import { paddingTop, textHeight } from "../measurement/position_measurement.js"
import { paddingTop, textHeight, charWidth } from "../measurement/position_measurement.js"
import { ie, ie_version } from "../util/browser.js"

// Read the actual heights of the rendered lines, and update their
Expand All @@ -9,7 +9,8 @@ export function updateHeightsInViewport(cm) {
let display = cm.display
let prevBottom = display.lineDiv.offsetTop
for (let i = 0; i < display.view.length; i++) {
let cur = display.view[i], height
let cur = display.view[i], wrapping = cm.options.lineWrapping
let height, width = 0
if (cur.hidden) continue
if (ie && ie_version < 8) {
let bot = cur.node.offsetTop + cur.node.offsetHeight
Expand All @@ -18,6 +19,10 @@ export function updateHeightsInViewport(cm) {
} else {
let box = cur.node.getBoundingClientRect()
height = box.bottom - box.top
// Check that lines don't extend past the right of the current
// editor width
if (!wrapping && cur.text.firstChild)
width = cur.text.firstChild.getBoundingClientRect().right - box.left - 1
}
let diff = cur.line.height - height
if (height < 2) height = textHeight(display)
Expand All @@ -27,6 +32,14 @@ export function updateHeightsInViewport(cm) {
if (cur.rest) for (let j = 0; j < cur.rest.length; j++)
updateWidgetHeight(cur.rest[j])
}
if (width > cm.display.sizerWidth) {
let chWidth = Math.ceil(width / charWidth(cm.display))
if (chWidth > cm.display.maxLineLength) {
cm.display.maxLineLength = chWidth
cm.display.maxLine = cur.line
cm.display.maxLineChanged = true
}
}
}
}

Expand Down

0 comments on commit 51a3704

Please sign in to comment.