Skip to content

Commit e080792

Browse files
add directive builder function and modify newFile handler
1 parent 9ce3fc8 commit e080792

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/lib/directive.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
function device(type){
4+
return `'{$STAMP ${type}}`;
5+
}
6+
7+
function pbasic(ver){
8+
return `'{$PBASIC ${ver}}`;
9+
}
10+
11+
function directive(board, language){
12+
return `${device(board)}\n${pbasic(language)}\n\n`;
13+
}
14+
15+
module.exports = directive;

src/plugins/handlers.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const consoleStore = require('../console-store');
1212
const Terminal = require('../lib/terminal');
1313
const Documents = require('../lib/documents');
1414
const highlighter = require('../lib/highlighter');
15+
const directive = require('../lib/directive');
1516

1617
const {
1718
NEW_FILE,
@@ -102,11 +103,14 @@ function handlers(app, opts, done){
102103
return;
103104
}
104105

105-
workspace.newFile(builtName, '')
106+
const insertDirective = directive('BS2', 2.5);
107+
108+
workspace.newFile(builtName, insertDirective)
106109
.then(() => userConfig.set('last-file', builtName))
107110
.then(function(){
108-
documents.create(path.join(cwd, builtName), '');
111+
documents.create(path.join(cwd, builtName), insertDirective);
109112
documents.focus();
113+
goDocEnd();
110114
});
111115
}
112116

@@ -292,6 +296,10 @@ function handlers(app, opts, done){
292296
cm.execCommand('replace');
293297
}
294298

299+
function goDocEnd(){
300+
cm.execCommand('goDocEnd');
301+
}
302+
295303
function moveByScrollUpLine(){
296304
const scrollbox = cm.getScrollInfo();
297305
cm.scrollTo(null, scrollbox.top - cm.defaultTextHeight());

0 commit comments

Comments
 (0)