Refactor userKeypress flag in index.html; working as expected now.
This commit is contained in:
		
							parent
							
								
									603a9fd3e8
								
							
						
					
					
						commit
						0f3e173a5b
					
				@ -63,8 +63,8 @@
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
    // Add my .vimrc stuff.
 | 
					    // Add my .vimrc stuff.
 | 
				
			||||||
    CodeMirror.Vim.map('jj', '<Esc>', 'insert')
 | 
					    CodeMirror.Vim.map('jj', '<Esc>', 'insert')
 | 
				
			||||||
    // Hacked semi-colon/colon swap remap into /assets/keymap/vim.js...kind of a heavy hammer might bite me later.
 | 
					    // Hacked semi-colon/colon swap remap into /assets/keymap/vim.js...a heavy-handed fix.
 | 
				
			||||||
    // ...and it's already confused me later the same day. I deleted ~/notes.kaplon.us/CodeMirror w/out realizing I'd symlinked it into /assets!
 | 
					    // Note, ~/notes.kaplon.us/CodeMirror is symlinked it into /assets!
 | 
				
			||||||
    // This no worky, there's no concept of <leader> in CodeMirror, but i was hoping this would work-around it.
 | 
					    // This no worky, there's no concept of <leader> in CodeMirror, but i was hoping this would work-around it.
 | 
				
			||||||
    //CodeMirror.Vim.map(' c', '<Esc>o- [ ] ', 'normal')
 | 
					    //CodeMirror.Vim.map(' c', '<Esc>o- [ ] ', 'normal')
 | 
				
			||||||
    //CodeMirror.Vim.map(' x', '<ESC>;s/\[\s\]/[x]/g<CR>;noh<CR>', 'normal')
 | 
					    //CodeMirror.Vim.map(' x', '<ESC>;s/\[\s\]/[x]/g<CR>;noh<CR>', 'normal')
 | 
				
			||||||
@ -75,8 +75,7 @@
 | 
				
			|||||||
    var userKeypress = false;
 | 
					    var userKeypress = false;
 | 
				
			||||||
    var socket = io();
 | 
					    var socket = io();
 | 
				
			||||||
    socket.on('download allNotes', function(msg){
 | 
					    socket.on('download allNotes', function(msg){
 | 
				
			||||||
        //console.log(msg);
 | 
					        userKeypress = false;   // Set back to false to avoid infinite content update loop when server sends initial content or changes from another client.
 | 
				
			||||||
        userKeypress = false;   // Set this back to false, still getting infinite loop.
 | 
					 | 
				
			||||||
        var cursorPos = editor.getCursor();
 | 
					        var cursorPos = editor.getCursor();
 | 
				
			||||||
        var scrollTop = editor.getScrollerElement().scrollTop;
 | 
					        var scrollTop = editor.getScrollerElement().scrollTop;
 | 
				
			||||||
        editor.getDoc().setValue(msg);
 | 
					        editor.getDoc().setValue(msg);
 | 
				
			||||||
@ -88,10 +87,10 @@
 | 
				
			|||||||
    var typingTimer;
 | 
					    var typingTimer;
 | 
				
			||||||
    editor.on("changes", function() {
 | 
					    editor.on("changes", function() {
 | 
				
			||||||
        if (!userKeypress) { return; };  // Do nothing if no keys hit yet, avoids infinite loop since 'changes' event fires after initial websocket content loading.
 | 
					        if (!userKeypress) { return; };  // Do nothing if no keys hit yet, avoids infinite loop since 'changes' event fires after initial websocket content loading.
 | 
				
			||||||
        userKeypress = false;   // Set this back to false, still getting infinite loop.
 | 
					 | 
				
			||||||
        clearTimeout(typingTimer);
 | 
					        clearTimeout(typingTimer);
 | 
				
			||||||
        typingTimer = setTimeout(
 | 
					        typingTimer = setTimeout(
 | 
				
			||||||
        function() {
 | 
					        function() {
 | 
				
			||||||
 | 
					            userKeypress = false;   // Set back to false to avoid infinite content update loop when server sends initial content or changes from another client.
 | 
				
			||||||
            socket.emit('upload allNotes', editor.getValue());
 | 
					            socket.emit('upload allNotes', editor.getValue());
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        2000
 | 
					        2000
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user