Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live Mirror Editor position in Preview pane. #3484

Merged
merged 57 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
8ece547
Add live scrolling to keep the preview in sync with editor position.
dbolacksn May 18, 2024
b7dc47f
Add a Live Scroll lock/unlock below Brew/Source Jump buttons.
dbolacksn May 19, 2024
86887b5
Update Jump keys to match parent PR and shift live scrolling to scrol…
dbolacksn May 19, 2024
07f2e8b
Merge branch 'master' into Issue_241_Part_II
dbolacksn May 19, 2024
bacdd65
Add a CR.
dbolacksn May 19, 2024
835ca0d
WIP
dbolacksn May 20, 2024
77450ed
Merge branch 'master' into Issue_241_Part_II
dbolacksn May 21, 2024
e69132b
Constant a lookup.
dbolacksn May 21, 2024
a715c9e
Store livescrolling in local storage
dbolacksn Jun 3, 2024
cca79d4
Merge branch 'master' into Issue_241_Part_II
dbolacksn Jun 3, 2024
4818f70
Add additional visual hinting to liveScroll lock.
dbolacksn Jun 3, 2024
ea9f9a8
Missed a couple of variable repalcements.
dbolacksn Jun 3, 2024
510d8f4
Resolve timing issue with liveScroll on linking.
dbolacksn Jun 4, 2024
7e3f2a3
Merge branch 'master' into Issue_241_Part_II
dbolacksn Jun 27, 2024
19ee3d6
Merge branch 'master' into Issue_241_Part_II
dbolacksn Jul 8, 2024
1844626
Merge branch 'master' into Issue_241_Part_II
dbolacksn Jul 30, 2024
dcdc8b4
Remove Livescrolling toggle hot-key.
dbolacksn Jul 30, 2024
b340276
Move livescrollToggle function out into a class method instead of an …
dbolacksn Jul 30, 2024
f10ef2b
Merge branch 'master' into Issue_241_Part_II
dbolacksn Aug 1, 2024
0057e2b
Merge branch 'master' into Issue_241_Part_II
dbolacksn Aug 2, 2024
2d781f0
Merge branch 'master' into Issue_241_Part_II
dbolacksn Aug 13, 2024
17b22b8
Merge branch 'master' into Issue_241_Part_II
dbolacksn Aug 15, 2024
78c4061
Merge branch 'master' into Issue_241_Part_II
dbolacksn Aug 20, 2024
fa63f1d
Merge branch 'master' into Issue_241_Part_II
dbolacksn Aug 20, 2024
5431d3e
Merge branch 'master' into Issue_241_Part_II
dbolacksn Aug 22, 2024
6952933
Fix merge
dbolacksn Aug 22, 2024
e27e61a
Bind livescrolling when done via scrollbars.
dbolacksn Aug 24, 2024
f24e477
Merge branch 'master' into Issue_241_Part_II
dbolacksn Aug 24, 2024
a4f30d6
Merge branch 'master' into Issue_241_Part_II
dbolacksn Aug 29, 2024
82f2d02
Merge branch 'master' into Issue_241_Part_II
dbolacksn Aug 31, 2024
b124e55
Merge branch 'master' into Issue_241_Part_II
calculuschild Sep 7, 2024
7a37bf4
Bodge Render side mirroring back into place.
dbolacksn Sep 8, 2024
fa74fb4
Update tooltips for locking.
dbolacksn Sep 8, 2024
1e9c742
Fix "clicked on the toggle ring" crash with scroll lock.
dbolacksn Sep 8, 2024
707b90e
Merge branch 'master' into pr/3484
calculuschild Sep 10, 2024
51c8973
Move `onClick` from the lock icon to the whole button
calculuschild Sep 10, 2024
0fbb487
Set button appearance based on state
calculuschild Sep 10, 2024
3152964
Remove setting button styles in `componentDidMount`
calculuschild Sep 10, 2024
b5155ed
remove unused variable
calculuschild Sep 10, 2024
ec74b99
Simplify `scroll` event for source editor using lodash Throttle
calculuschild Sep 10, 2024
45a9501
Jump based on scroll position, not cursor position
calculuschild Sep 10, 2024
e5ab223
Better line position (viewport has some margin)
calculuschild Sep 10, 2024
8fa5eeb
Merge branch 'master' into Issue_241_Part_II
dbolacksn Sep 10, 2024
7d29856
Add Pagella face to Blank Template.
dbolacksn Sep 11, 2024
84d237e
Revert "Add Pagella face to Blank Template."
dbolacksn Sep 11, 2024
3ef91cb
Add check for scroll event complete/ lift page state up
calculuschild Sep 12, 2024
d4fa5d5
Merge branch 'master' into pr/3484
calculuschild Sep 14, 2024
181c6bf
Update editor.jsx
calculuschild Sep 14, 2024
84c0242
Put page jump checks in componentDidUpdate
calculuschild Sep 15, 2024
dbe56ab
Merge branch 'master' of github.com:naturalcrit/homebrewery
dbolacksn Sep 15, 2024
3388fcc
Merge branch 'master' into Issue_241_Part_II
dbolacksn Sep 15, 2024
85401ba
Fix BrewRenderer scrolling to 0
calculuschild Sep 16, 2024
81ab941
Clean up unused code
calculuschild Sep 16, 2024
c07c02f
Remove unused variable
calculuschild Sep 16, 2024
a353425
More cleanup
calculuschild Sep 16, 2024
25a40e3
Remove console logs
calculuschild Sep 16, 2024
48bdc41
More logic simplification
calculuschild Sep 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions client/homebrew/editor/editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ const DEFAULT_STYLE_TEXT = dedent`
color: black;
}`;

let lastPage = 0;
let liveScroll = true;

const isElementCodeMirror=(element)=>{
let el = element;
while( el.tagName != 'body' ) {
if ( !el?.classList ) return false
if( el?.classList?.contains('CodeMirror-code') || el.classList.contains('CodeMirror-line'))
return true;
el = el.parentNode;
}
return false;
};

const Editor = createClass({
displayName : 'Editor',
Expand All @@ -31,6 +44,7 @@ const Editor = createClass({
text : '',
style : ''
},
liveScroll : true,

onTextChange : ()=>{},
onStyleChange : ()=>{},
Expand All @@ -56,6 +70,16 @@ const Editor = createClass({
this.updateEditorSize();
this.highlightCustomMarkdown();
window.addEventListener('resize', this.updateEditorSize);
document.addEventListener('keydown', this.handleControlKeys);
document.addEventListener('click', (e)=>{
if(isElementCodeMirror(e.target) && liveScroll ) {
const curPage = this.getCurrentPage();
if( curPage != lastPage ) {
this.brewJump();
lastPage = curPage;
}
}
});

const editorTheme = window.localStorage.getItem(EDITOR_THEME_KEY);
if(editorTheme) {
Expand All @@ -77,8 +101,48 @@ const Editor = createClass({
if(prevProps.moveSource !== this.props.moveSource) {
this.sourceJump();
};
if(prevProps.liveScroll !== this.props.liveScroll) {
liveScroll = !liveScroll;
};
},

handleControlKeys : function(e){
if(liveScroll) {
const movementKeys = [ 13, 33, 34, 37, 38, 39, 40 ];
if (movementKeys.includes(e.keyCode)) {
const curPage = this.getCurrentPage();
if( curPage != lastPage ) {
this.brewJump();
lastPage = curPage;
}
}
}
const M_KEY = 77;
const END_KEY = 35;
const HOME_KEY = 36;
const SCROLLLOCK_KEY = 145;

// Toggle Live-scrolling on Scroll Lock
if(e.keyCode == SCROLLLOCK_KEY) {
liveScroll = !liveScroll;
}
if(!(e.ctrlKey || e.metaKey)) return;

// Handle CTRL-HOME and CTRL-END
if(((e.keyCode == END_KEY) || (e.keyCode == HOME_KEY)) && liveScroll) this.brewJump();

// Brew Jump on CTRL-J
if((!e.shiftKey) && (e.keyCode == M_KEY)) this.brewJump();
// Source Jump on Shift-CTRL-J
if ((e.shiftKey) && (!e.altKey) && (e.keyCode == M_KEY)) this.sourceJump();

if( e.keyCode == M_KEY) {
e.stopPropagation();
e.preventDefault();
}
},


updateEditorSize : function() {
if(this.refs.codeEditor) {
let paneHeight = this.refs.main.parentNode.clientHeight;
Expand Down Expand Up @@ -116,6 +180,7 @@ const Editor = createClass({
const codeMirror = this.refs.codeEditor.codeMirror;

codeMirror.operation(()=>{ // Batch CodeMirror styling

//reset custom text styles
const customHighlights = codeMirror.getAllMarks().filter((mark)=>!mark.__isFold); //Don't undo code folding
for (let i=customHighlights.length - 1;i>=0;i--) customHighlights[i].clear();
Expand Down
16 changes: 16 additions & 0 deletions shared/naturalcrit/splitPane/splitPane.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const SplitPane = createClass({
isDragging : false,
moveSource : false,
moveBrew : false,
liveScroll : true,
showMoveArrows : true
};
},
Expand Down Expand Up @@ -117,6 +118,20 @@ const SplitPane = createClass({
onClick={()=>this.setState({ moveBrew: !this.state.moveBrew })} >
<i className='fas fa-arrow-right' />
</div>
<div id='scrollToggleDiv' className='arrow unlock'
style={{ left: this.state.currentDividerPos-4 }}
onClick={()=>{
this.setState({ liveScroll: !this.state.liveScroll });
if(document.getElementById('scrollToggle').classList.contains('fa-unlock')) {
document.getElementById('scrollToggle').className = 'fas fa-lock';
dbolack-ab marked this conversation as resolved.
Show resolved Hide resolved
document.getElementById('scrollToggleDiv').className = 'arrow lock';
} else {
document.getElementById('scrollToggle').className = 'fas fa-unlock';
document.getElementById('scrollToggleDiv').className = 'arrow unlock';
}
}} >
<i id='scrollToggle' className='fas fa-unlock' />
</div>
</>;
}
},
Expand All @@ -143,6 +158,7 @@ const SplitPane = createClass({
{React.cloneElement(this.props.children[0], {
moveBrew : this.state.moveBrew,
moveSource : this.state.moveSource,
liveScroll : this.state.liveScroll,
setMoveArrows : this.setMoveArrows
})}
</Pane>
Expand Down
8 changes: 8 additions & 0 deletions shared/naturalcrit/splitPane/splitPane.less
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@
.tooltipRight('Jump to location in Preview');
top : 60px;
}
&.lock{
.tooltipRight('Lock cursor tracking between windows.');
top : 90px;
}
&.unlock{
.tooltipRight('Unlock cursor tracking between windows.');
top : 90px;
}
&:hover{
background-color: #666;
}
Expand Down