Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitca117d8

Browse files
committed
add docs & tests for editor. improve editor open perf
1 parente10e386 commitca117d8

File tree

14 files changed

+123
-91
lines changed

14 files changed

+123
-91
lines changed

‎lib/modules/alert/index.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
vartypes_1=require('./types');
3-
varcolors={
3+
exports.colors={
44
PASS:'#73C990',
55
FAIL:'#FF4081',
66
NOTE:'#9DA5B4',
@@ -10,7 +10,7 @@ exports._alert = {
1010
open:false,
1111
action:'NOTE',
1212
duration:1500,
13-
color:colors.NOTE
13+
color:exports.colors.NOTE
1414
};
1515
varopen={
1616
open:true,
@@ -19,7 +19,7 @@ var open = {
1919
};
2020
varcurrent=exports._alert;
2121
functionsetAlert(a){
22-
a.color=colors[a.action]||colors.NOTE;
22+
a.color=exports.colors[a.action]||exports.colors.NOTE;
2323
varstatusBarAlert=document.getElementsByClassName('cr-alert-replay')[0];
2424
statusBarAlert.style.color=a.color;
2525
current=a;

‎lib/modules/editor/actions/file.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ exports.save = save;
1111
functionopen(file,options){
1212
if(options===void0){options={};}
1313
returnnewPromise(function(resolve,reject){
14-
varopenTimeout=300;
1514
atom.workspace.open(file,options);
16-
setTimeout(function(){returnresolve();},openTimeout);
15+
atom.workspace.onDidOpen(function(){returnresolve();});
1716
});
1817
}
1918
exports.open=open;

‎lib/modules/editor/actions/writeFile.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var path_1 = require('path');
55
functionwriteFileFromContent(_a){
66
varto=_a.to,content=_a.content,dir=_a.dir;
77
vartoAbs=path_1.join(dir,to);
8-
createFolders({dir:dir,to:to}).then(function(){
8+
createFolder({dir:dir,to:to}).then(function(){
99
fs_1.writeFile(toAbs,content,function(writeErr){
1010
if(writeErr){
1111
console.log("Error: tried but failed to write to "+toAbs+" with: "+content,writeErr);
@@ -19,7 +19,7 @@ function writeFileFromFile(_a) {
1919
varto=_a.to,from=_a.from,dir=_a.dir,tutorialDir=_a.tutorialDir;
2020
vartoAbs=path_1.join(dir,to);
2121
varfromAbs=path_1.join(tutorialDir,from);
22-
createFolders({dir:dir,to:to}).then(function(){
22+
createFolder({dir:dir,to:to}).then(function(){
2323
fs_1.readFile(fromAbs,'utf8',function(readErr,data){
2424
varerr="Error: tried to write '"+fromAbs+"' to '"+toAbs+"' but failed.";
2525
if(readErr){
@@ -35,7 +35,7 @@ function writeFileFromFile(_a) {
3535
});
3636
}
3737
exports.writeFileFromFile=writeFileFromFile;
38-
functioncreateFolders(_a){
38+
functioncreateFolder(_a){
3939
vardir=_a.dir,to=_a.to;
4040
returnnewPromise(function(resolve,reject){
4141
varfolders=to.split('/').slice(0,-1);

‎src/modules/dir/reducer.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/// <reference path="../../typings/globals/jest/index.d.ts" />
2+
/// <reference path="../../typings/common/global.d.ts" />
3+
14
importdirfrom'./index';
25
import{atomPath}from'../../__tests__/mocks/atom';
36

@@ -10,11 +13,11 @@ describe('dir reducer', () => {
1013
it('should return the project directory in Atom',()=>{
1114
constpathToDir='./path/to/dir';
1215
global.atom=atomPath(pathToDir);
13-
expect(dir()).toBe(pathToDir);
16+
expect(dir('')).toBe(pathToDir);
1417
});
1518

1619
it('should throw an error if no project directory is found',()=>{
17-
expect(()=>dir()).toThrowError(/Noprojectdirectory/);
20+
expect(()=>dir('')).toThrowError(/Noprojectdirectory/);
1821
});
1922

2023
});

‎src/modules/editor/Save/index.tsx‎

Lines changed: 0 additions & 33 deletions
This file was deleted.

‎src/modules/editor/ToggleDevTools/index.tsx‎

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1+
/**
2+
* Toggle atom devtools console
3+
*@returns void
4+
*/
15
exportfunctiontoggleDevTools():void{
26
atom.toggleDevTools();
37
}
48

9+
/**
10+
* Clear atom devtools console
11+
*@returns void
12+
*/
513
exportfunctionclearConsole():void{
614
atom.executeJavaScriptInDevTools(console.clear());
715
}
816

17+
/**
18+
* Open atom devtools
19+
*@returns void
20+
*/
921
exportfunctionopenDevTools():void{
1022
atom.openDevTools();
1123
}

‎src/modules/editor/actions/editor.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Get the current active atom editor
3+
*@returns Promise
4+
*/
15
exportfunctiongetEditor():Promise<AtomCore.IEditor>{
26
returnnewPromise((resolve,reject)=>{
37
consteditor=atom.workspace.getActiveTextEditor();

‎src/modules/editor/actions/file.ts‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,44 @@ import {unlink} from 'fs';
33
import{getEditor}from'./editor';
44
importfileExistsfrom'node-file-exists';
55

6+
/**
7+
* Open a new folder in atom
8+
*@returns void
9+
*/
610
exportfunctionopenFolder():void{
711
atom.open();
812
}
913

10-
exportfunctionsave(){
14+
/**
15+
* Saves the current editor
16+
*@returns void
17+
*/
18+
exportfunctionsave():void{
1119
getEditor().then(editor=>editor.save());
1220
}
1321

22+
/**
23+
* Opens a file
24+
* https://atom.io/docs/api/v1.10.2/Workspace#instance-open
25+
*@param {string} file file name
26+
*@param {} options={} file open options
27+
*@returns Promise
28+
*/
1429
exportfunctionopen(file:string,options={}):Promise<any>{
1530
returnnewPromise((resolve,reject)=>{
16-
// delete file first, to avoid bug
17-
// if (fileExists(file)) {
18-
// unlink(file);
19-
// }
20-
// delay necessary since opening a file is slow
21-
constopenTimeout=300;
2231
atom.workspace.open(file,options);
23-
setTimeout(()=>resolve(),openTimeout);
32+
// resolve when file opens
33+
// https://atom.io/docs/api/v1.10.2/Workspace#instance-onDidOpen
34+
atom.workspace.onDidOpen(()=>resolve());
2435
});
2536
}
2637

27-
exportfunctionscroll(content:string):Promise<void>{
38+
/**
39+
* Scroll to cursor position
40+
*@param {string} content text editor content
41+
*@returns Promise
42+
*/
43+
exportfunctionscroll(content:string):any{
2844
returngetEditor().then((editor:AtomCore.IEditor)=>{
2945
constregex=newRegExp(
3046
content.replace(/[\\\.\+\*\?\^\$\[\]\(\)\{\}\/\'\#\:\!\=\|]/ig,'\\$&'),'gm'

‎src/modules/editor/actions/tabs.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* close all other tabs
3+
*@returns void
4+
*/
15
exportfunctioncloseAllPanels():void{
26
leteditors:AtomCore.IEditor[]=atom.workspace.getTextEditors();
37
editors.forEach((editor:AtomCore.IEditor)=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp