mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-07 14:12:43 +00:00
remove "in viewport" requirement for markdown highlight/pg numbers
This commit is contained in:
@@ -115,11 +115,6 @@ const Editor = createClass({
|
|||||||
|
|
||||||
let editorPageCount = 2; // start page count from page 2
|
let editorPageCount = 2; // start page count from page 2
|
||||||
|
|
||||||
// get top and bottom line numbers currently in editor viewport
|
|
||||||
const viewportRect = codeMirror.getWrapperElement().getBoundingClientRect();
|
|
||||||
const topVisibleLine = codeMirror.lineAtHeight(viewportRect.top, 'window') - 50;
|
|
||||||
const bottomVisibleLine = codeMirror.lineAtHeight(viewportRect.bottom, 'window') + 50;
|
|
||||||
|
|
||||||
_.forEach(this.props.brew.text.split('\n'), (line, lineNumber)=>{
|
_.forEach(this.props.brew.text.split('\n'), (line, lineNumber)=>{
|
||||||
|
|
||||||
//reset custom line styles
|
//reset custom line styles
|
||||||
@@ -129,17 +124,15 @@ const Editor = createClass({
|
|||||||
// Legacy Codemirror styling
|
// Legacy Codemirror styling
|
||||||
if(this.props.renderer == 'legacy') {
|
if(this.props.renderer == 'legacy') {
|
||||||
if(line.includes('\\page')){
|
if(line.includes('\\page')){
|
||||||
// add a check here to see if in current viewport
|
// add back the original class 'background' but also add the new class '.pageline'
|
||||||
if(lineNumber > topVisibleLine && lineNumber < bottomVisibleLine){
|
codeMirror.addLineClass(lineNumber, 'background', 'pageLine');
|
||||||
// add back the original class 'background' but also add the new class '.pageline'
|
const pageCountElement = Object.assign(document.createElement('span'), {
|
||||||
codeMirror.addLineClass(lineNumber, 'background', 'pageLine');
|
className : 'editor-page-count',
|
||||||
const pageCountElement = Object.assign(document.createElement('span'), {
|
textContent : editorPageCount
|
||||||
className : 'editor-page-count',
|
});
|
||||||
textContent : editorPageCount
|
codeMirror.setBookmark({ line: lineNumber, ch: line.length }, pageCountElement);
|
||||||
});
|
|
||||||
codeMirror.setBookmark({ line: lineNumber, ch: line.length }, pageCountElement);
|
editorPageCount += 1;
|
||||||
}
|
|
||||||
editorPageCount = editorPageCount + 1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -147,8 +140,6 @@ const Editor = createClass({
|
|||||||
// New Codemirror styling for V3 renderer
|
// New Codemirror styling for V3 renderer
|
||||||
if(this.props.renderer == 'V3') {
|
if(this.props.renderer == 'V3') {
|
||||||
if(line.match(/^\\page$/)){
|
if(line.match(/^\\page$/)){
|
||||||
// add a check here to see if in current viewport,
|
|
||||||
if(lineNumber > topVisibleLine && lineNumber < bottomVisibleLine){
|
|
||||||
// add back the original class 'background' but also add the new class '.pageline'
|
// add back the original class 'background' but also add the new class '.pageline'
|
||||||
codeMirror.addLineClass(lineNumber, 'background', 'pageLine');
|
codeMirror.addLineClass(lineNumber, 'background', 'pageLine');
|
||||||
const pageCountElement = Object.assign(document.createElement('span'), {
|
const pageCountElement = Object.assign(document.createElement('span'), {
|
||||||
@@ -156,8 +147,8 @@ const Editor = createClass({
|
|||||||
textContent : editorPageCount
|
textContent : editorPageCount
|
||||||
});
|
});
|
||||||
codeMirror.setBookmark({ line: lineNumber, ch: line.length }, pageCountElement);
|
codeMirror.setBookmark({ line: lineNumber, ch: line.length }, pageCountElement);
|
||||||
}
|
|
||||||
editorPageCount = editorPageCount + 1;
|
editorPageCount += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(line.match(/^\\column$/)){
|
if(line.match(/^\\column$/)){
|
||||||
|
|||||||
@@ -114,7 +114,6 @@ const CodeEditor = createClass({
|
|||||||
|
|
||||||
// Note: codeMirror passes a copy of itself in this callback. cm === this.codeMirror. Either one works.
|
// Note: codeMirror passes a copy of itself in this callback. cm === this.codeMirror. Either one works.
|
||||||
this.codeMirror.on('change', (cm)=>{this.props.onChange(cm.getValue());});
|
this.codeMirror.on('change', (cm)=>{this.props.onChange(cm.getValue());});
|
||||||
this.codeMirror.on('viewportChange', _.debounce((cm)=>{this.props.onChange(cm.getValue());}, 200));
|
|
||||||
this.updateSize();
|
this.updateSize();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user