Add printing. Fixes #120
This commit is contained in:
parent
0b2aaf1883
commit
1767cd3fc2
2 changed files with 21 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
|||
{ "label": "Save As", "command": "session:save-file-as" },
|
||||
{ "label": "Revert", "command": "session:revert-file" },
|
||||
{ "label": "Close", "command": "session:close-tab" },
|
||||
{ "label": "Print", "command": "editor:print" },
|
||||
{ "label": "Exit", "command": "app:exit" }
|
||||
]
|
||||
},
|
||||
|
|
20
js/editor.js
20
js/editor.js
|
@ -84,6 +84,26 @@ define([
|
|||
//disable focusing on the editor except by program
|
||||
document.find("textarea").setAttribute("tabindex", -1);
|
||||
|
||||
command.on("editor:print", function(c) {
|
||||
ace.require("ace/config").loadModule("ace/ext/static_highlight", function(static) {
|
||||
var session = editor.getSession();
|
||||
var printable = static.renderSync(session.getValue(), session.getMode(), editor.renderer.theme);
|
||||
var iframe = document.createElement("iframe");
|
||||
var css = "<style>" + printable.css + "</style>";
|
||||
var doc = css + printable.html;
|
||||
iframe.srcdoc = doc;
|
||||
iframe.width = iframe.height = 1;
|
||||
iframe.style.display = "none";
|
||||
document.body.append(iframe);
|
||||
setTimeout(function() {
|
||||
iframe.contentWindow.print();
|
||||
setTimeout(function() {
|
||||
iframe.remove();
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return editor;
|
||||
|
||||
});
|
Loading…
Reference in a new issue