summaryrefslogtreecommitdiff
path: root/public/js
diff options
context:
space:
mode:
authorYukai Huang2017-03-28 12:10:35 +0800
committerYukai Huang2017-03-28 12:10:35 +0800
commitd7c068cbfdc8d6173ea722ce02f9151d8e5ff807 (patch)
tree7b3bca2e021afc6e6cb2db0a5d4cb6decb84d206 /public/js
parentb86ecb1342673628151f729edc0c8714b1d07de0 (diff)
Rewrite cursorActivity with multi listener style
- adjust function order to prevent standard lint failure
Diffstat (limited to 'public/js')
-rw-r--r--public/js/index.js34
1 files changed, 17 insertions, 17 deletions
diff --git a/public/js/index.js b/public/js/index.js
index 6754a92d..4059431d 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -2699,10 +2699,23 @@ editorInstance.on('focus', function (cm) {
window.personalInfo['cursor'] = editor.getCursor()
socket.emit('cursor focus', editor.getCursor())
})
-editorInstance.on('cursorActivity', function (cm) {
- updateStatusBar()
- cursorActivity()
-})
+
+const cursorActivity = _.debounce(cursorActivityInner, cursorActivityDebounce)
+
+function cursorActivityInner () {
+ if (editorHasFocus() && !Visibility.hidden()) {
+ for (var i = 0; i < window.onlineUsers.length; i++) {
+ if (window.onlineUsers[i].id === window.personalInfo.id) {
+ window.onlineUsers[i].cursor = editor.getCursor()
+ }
+ }
+ window.personalInfo['cursor'] = editor.getCursor()
+ socket.emit('cursor activity', editor.getCursor())
+ }
+}
+
+editorInstance.on('cursorActivity', updateStatusBar)
+editorInstance.on('cursorActivity', cursorActivity)
editorInstance.on('beforeSelectionChange', updateStatusBar)
editorInstance.on('beforeSelectionChange', function (doc, selections) {
@@ -2737,19 +2750,6 @@ editorInstance.on('beforeSelectionChange', function (doc, selections) {
}
})
-var cursorActivity = _.debounce(cursorActivityInner, cursorActivityDebounce)
-
-function cursorActivityInner () {
- if (editorHasFocus() && !Visibility.hidden()) {
- for (var i = 0; i < window.onlineUsers.length; i++) {
- if (window.onlineUsers[i].id === window.personalInfo.id) {
- window.onlineUsers[i].cursor = editor.getCursor()
- }
- }
- window.personalInfo['cursor'] = editor.getCursor()
- socket.emit('cursor activity', editor.getCursor())
- }
-}
editorInstance.on('blur', function (cm) {
for (var i = 0; i < window.onlineUsers.length; i++) {
if (window.onlineUsers[i].id === window.personalInfo.id) {