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

Commitc93d997

Browse files
committed
fix getEditor cannot find issue
1 parent959dcb2 commitc93d997

File tree

7 files changed

+144
-10
lines changed

7 files changed

+144
-10
lines changed

‎lib/atom/actions/editor.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ function getEditor() {
77
getEditorCount+=1;
88
setTimeout(function(){
99
editor=atom.workspace.getActiveTextEditor();
10-
});
11-
if(getEditorCount>999){
12-
console.log('Failed to find active editor');
13-
reject(null);
10+
},10);
11+
if(getEditorCount>1000){
12+
console.log('Cannot find active text editor');
13+
setTimeout(function(){
14+
editor=atom.workspace.getActiveTextEditor();
15+
},100);
1416
}
1517
}
1618
resolve(editor);

‎lib/atom/actions/file.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ function open(filePath, options) {
1616
if(exists_1.fileExists(filePath)){
1717
fs_1.unlink(filePath);
1818
}
19-
resolve(atom.workspace.open(filePath,options));
19+
atom.workspace.open(filePath,options);
20+
setTimeout(function(){
21+
resolve();
22+
},200);
2023
});
2124
}
2225
exports.open=open;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"use strict";
2+
vareditor_1=require('../../atom/editor');
3+
varaction_helpers_1=require('./action-helpers');
4+
varType={
5+
OPEN:'open',
6+
SET:'set',
7+
INSERT:'insert',
8+
OPEN_CONSOLE:'openConsole',
9+
};
10+
functioneditorActions(actionString){
11+
returnnewPromise(function(resolve,reject){
12+
varcommand=action_helpers_1.getCommand(actionString);
13+
varparams=action_helpers_1.getParams(actionString);
14+
switch(command){
15+
caseType.OPEN:
16+
varobj=action_helpers_1.getOptions(params[0]);
17+
varfile=obj.param;
18+
varoptions=obj.options;
19+
if(params.length===1){
20+
editor_1.open(file,options);
21+
setTimeout(function(){
22+
resolve();
23+
},100);
24+
}
25+
break;
26+
caseType.SET:
27+
if(params.length===1){
28+
varcontent_1=params[0];
29+
setTimeout(function(){
30+
editor_1.set(content_1);
31+
resolve(true);
32+
});
33+
}
34+
break;
35+
caseType.INSERT:
36+
if(params.length===1){
37+
varcontent_2=params[0];
38+
setTimeout(function(){
39+
editor_1.insert(content_2,{});
40+
resolve(true);
41+
});
42+
}
43+
break;
44+
caseType.OPEN_CONSOLE:
45+
if(params.length===0){
46+
setTimeout(function(){
47+
editor_1.openDevTools();
48+
resolve(true);
49+
});
50+
}
51+
break;
52+
default:
53+
console.log('Invalid editor action command');
54+
reject(false);
55+
}
56+
}).catch(function(err){
57+
console.error('Error with editor',err);
58+
});
59+
}
60+
exports.editorActions=editorActions;

‎src/atom/actions/editor.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ export function getEditor(): Promise<AtomCore.IEditor> {
66
getEditorCount+=1;
77
setTimeout(function(){
88
editor=atom.workspace.getActiveTextEditor();
9-
});
10-
if(getEditorCount>999){
11-
console.log('Failed to find active editor');
12-
reject(null);
9+
},10);
10+
if(getEditorCount>1000){
11+
console.log('Cannot find active text editor');
12+
setTimeout(()=>{
13+
editor=atom.workspace.getActiveTextEditor();
14+
},100);
1315
}
1416
}
1517
resolve(editor);

‎src/atom/actions/file.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export function open(filePath: string, options = {}): Promise<any> {
1616
if(fileExists(filePath)){
1717
unlink(filePath);
1818
}
19-
resolve(atom.workspace.open(filePath,options));
19+
atom.workspace.open(filePath,options);
20+
setTimeout(()=>{
21+
resolve();
22+
},200);// delay necessary since opening a file is slow
2023
});
2124
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import{open,set,insert,openDevTools}from'../../atom/editor';
2+
import{getCommand,getParams,getOptions}from'./action-helpers';
3+
4+
constType={
5+
OPEN:'open',
6+
SET:'set',
7+
INSERT:'insert',
8+
OPEN_CONSOLE:'openConsole',
9+
};
10+
11+
exportfunctioneditorActions(actionString:string):Promise<void>{
12+
returnnewPromise((resolve,reject)=>{
13+
letcommand:string=getCommand(actionString);
14+
letparams:string[]=getParams(actionString);
15+
switch(command){
16+
caseType.OPEN:
17+
letobj=getOptions(params[0]);
18+
letfile=obj.param;
19+
letoptions=obj.options;
20+
if(params.length===1){
21+
open(file,options);
22+
setTimeout(function(){
23+
resolve();
24+
},100);
25+
}
26+
break;
27+
caseType.SET:
28+
if(params.length===1){
29+
letcontent=params[0];
30+
31+
setTimeout(function(){
32+
set(content);
33+
resolve(true);
34+
});
35+
}
36+
break;
37+
caseType.INSERT:
38+
if(params.length===1){
39+
// let obj = getOptions(params[0]);
40+
letcontent:string=params[0];
41+
// let options: object = obj.options;
42+
setTimeout(function(){
43+
insert(content,{});
44+
resolve(true);
45+
});
46+
}
47+
break;
48+
caseType.OPEN_CONSOLE:
49+
if(params.length===0){
50+
setTimeout(function(){
51+
openDevTools();
52+
resolve(true);
53+
});
54+
}
55+
break;
56+
default:
57+
console.log('Invalid editor action command');
58+
reject(false);
59+
}
60+
}).catch((err)=>{
61+
console.error('Error with editor',err);
62+
});
63+
}

‎tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"src/reducers/checks/verify.ts",
8686
"src/reducers/dir/index.ts",
8787
"src/reducers/editor-actions/action-helpers.ts",
88+
"src/reducers/editor-actions/action-reducer.ts",
8889
"src/reducers/editor-actions/actions.ts",
8990
"src/reducers/editor-actions/index.ts",
9091
"src/reducers/editor-actions/parser.ts",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp