Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
88de9e40
Commit
88de9e40
authored
13 years ago
by
Tom Needham
Browse files
Options
Downloads
Patches
Plain Diff
Keyboard shortcuts for saving. Refined code.
parent
c3388477
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/files_texteditor/js/editor.js
+46
-13
46 additions, 13 deletions
apps/files_texteditor/js/editor.js
with
46 additions
and
13 deletions
apps/files_texteditor/js/editor.js
+
46
−
13
View file @
88de9e40
...
...
@@ -77,8 +77,10 @@ function updateSessionFileHash(path){
"
json
"
);
}
var
editor_is_saving
=
false
;
function
doFileSave
(){
if
(
is_editor_shown
){
editor_is_saving
=
true
;
$
(
'
#editor_save
'
).
after
(
'
<img id="saving_icon" src="
'
+
OC
.
filePath
(
'
core
'
,
'
img
'
,
'
loading.gif
'
)
+
'
"></img>
'
);
var
filecontents
=
window
.
aceEditor
.
getSession
().
getValue
();
var
dir
=
$
(
'
#editor
'
).
attr
(
'
data-dir
'
);
...
...
@@ -93,7 +95,10 @@ function doFileSave(){
$
(
'
#saving_icon
'
).
remove
();
$
(
'
#editor_save
'
).
after
(
'
<p id="save_result" style="float: left">Saved!</p>
'
)
setTimeout
(
function
()
{
$
(
'
#save_result
'
).
remove
();
$
(
'
#save_result
'
).
fadeOut
(
'
slow
'
,
function
(){
$
(
this
).
remove
();
editor_is_saving
=
false
;
});
},
2000
);
}
else
{
...
...
@@ -101,7 +106,10 @@ function doFileSave(){
$
(
'
#saving_icon
'
).
remove
();
$
(
'
#editor_save
'
).
after
(
'
<p id="save_result" style="float: left">Failed!</p>
'
);
setTimeout
(
function
()
{
$
(
'
#save_result
'
).
fadeOut
(
'
slow
'
,
function
(){
$
(
this
).
remove
();
});
$
(
'
#save_result
'
).
fadeOut
(
'
slow
'
,
function
(){
$
(
this
).
remove
();
editor_is_saving
=
false
;
});
},
2000
);
}
},
'
json
'
);
...
...
@@ -112,7 +120,10 @@ function doFileSave(){
// Temporary measure until we get a tick icon
$
(
'
#editor_save
'
).
after
(
'
<p id="save_result" style="float: left">Saved!</p>
'
);
setTimeout
(
function
()
{
$
(
'
#save_result
'
).
fadeOut
(
'
slow
'
,
function
(){
$
(
this
).
remove
();
});
$
(
'
#save_result
'
).
fadeOut
(
'
slow
'
,
function
(){
$
(
this
).
remove
();
editor_is_saving
=
false
;
});
},
2000
);
}
}
...
...
@@ -122,21 +133,17 @@ function doFileSave(){
// Temporary measure until we get a tick icon
$
(
'
#editor_save
'
).
after
(
'
<p id="save_result" style="float: left">Saved!</p>
'
);
setTimeout
(
function
()
{
$
(
'
#save_result
'
).
fadeOut
(
'
slow
'
,
function
(){
$
(
this
).
remove
();
});
$
(
'
#save_result
'
).
fadeOut
(
'
slow
'
,
function
(){
$
(
this
).
remove
();
editor_is_saving
=
false
;
});
},
2000
);
}
},
'
json
'
);
giveEditorFocus
();
}
else
{
$
(
'
#editor
'
).
data
(
'
editor
'
,
'
false
'
);
return
;
window
.
aceEditor
.
focus
();
}
};
function
giveEditorFocus
(){
window
.
aceEditor
.
focus
();
};
function
showFileEditor
(
dir
,
filename
){
if
(
!
is_editor_shown
){
// Loads the file editor and display it.
...
...
@@ -190,9 +197,31 @@ function hideFileEditor(){
}
}
// Keyboard Shortcuts
var
ctrlBtn
=
false
;
function
checkForCtrlKey
(
e
){
if
(
e
.
which
==
17
||
e
.
which
==
91
)
ctrlBtn
=
false
;
}
function
checkForSaveKeyPress
(
e
){
if
(
!
editor_is_saving
){
if
(
e
.
which
==
17
||
e
.
which
==
91
)
ctrlBtn
=
true
;
if
(
e
.
which
==
83
&&
ctrlBtn
==
true
)
{
e
.
preventDefault
();
doFileSave
();
return
false
;
}
}
else
{
e
.
preventDefault
();
}
}
// Sets the correct size of the editor window
$
(
window
).
resize
(
function
()
{
setEditorSize
();
});
var
is_editor_shown
=
false
;
$
(
document
).
ready
(
function
(){
...
...
@@ -220,4 +249,8 @@ $(document).ready(function(){
}
// Binds the file save and close editor events to the buttons
bindControlEvents
();
});
// Binds the save keyboard shortcut events
$
(
document
).
unbind
(
'
keyup
'
).
bind
(
'
keyup
'
,
checkForCtrlKey
).
unbind
(
'
keydown
'
).
bind
(
'
keydown
'
,
checkForSaveKeyPress
);
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment