Created
March 21, 2014 10:02
-
-
Save marijnh/9683027 to your computer and use it in GitHub Desktop.
CodeMirror merge view resize to fit content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mergeViewHeight(mergeView) { | |
function editorHeight(editor) { | |
if (!editor) return 0; | |
return editor.getScrollInfo().height; | |
} | |
return Math.max(editorHeight(mergeView.leftOriginal()), | |
editorHeight(mergeView.editor()), | |
editorHeight(mergeView.rightOriginal())); | |
} | |
function resize(mergeView) { | |
var height = mergeViewHeight(mergeView); | |
for(;;) { | |
if (mergeView.leftOriginal()) | |
mergeView.leftOriginal().setSize(null, height); | |
mergeView.editor().setSize(null, height); | |
if (mergeView.rightOriginal()) | |
mergeView.rightOriginal().setSize(null, height); | |
var newHeight = mergeViewHeight(mergeView); | |
if (newHeight >= height) break; | |
else height = newHeight; | |
} | |
mergeView.wrap.style.height = height + "px"; | |
} |
@marianopeck i found solution.
var mergeView = CodeMirror.MergeView(target, {
value: value,
orig: origLeft,
lineNumbers: false,
mode: 'gfm',
lineWrapping: true,
viewportMargin: Infinity,
highlightDifferences: true,
connect: true,
collapseIdentical: false,
revertButtons: true
})
resize(mergeView)
$(window).on('resize', function () {
resize(mergeView)
})
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I cannot seem to make it work this script. I am trying ti fit MergeView to its contents. I have added both functions but still cannot make it work. Any idea how can use it? Let's say I created code mirror this way:
dv = CodeMirror.MergeView( target , { ....