Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
abe753dd
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
abe753dd
编写于
1月 15, 2017
作者:
D
Daniel Imms
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean up old process and handle listeners better
Fixes #18377
上级
dbceda7d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
23 deletion
+37
-23
src/vs/workbench/parts/terminal/common/terminal.ts
src/vs/workbench/parts/terminal/common/terminal.ts
+1
-1
src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts
...bench/parts/terminal/electron-browser/terminalInstance.ts
+36
-22
未找到文件。
src/vs/workbench/parts/terminal/common/terminal.ts
浏览文件 @
abe753dd
...
@@ -271,5 +271,5 @@ export interface ITerminalInstance {
...
@@ -271,5 +271,5 @@ export interface ITerminalInstance {
*
*
* @param shell The new launch configuration.
* @param shell The new launch configuration.
*/
*/
reuseTerminal
(
shell
:
IShellLaunchConfig
):
void
;
reuseTerminal
(
shell
?
:
IShellLaunchConfig
):
void
;
}
}
src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts
浏览文件 @
abe753dd
...
@@ -45,7 +45,8 @@ export class TerminalInstance implements ITerminalInstance {
...
@@ -45,7 +45,8 @@ export class TerminalInstance implements ITerminalInstance {
private
_processId
:
number
;
private
_processId
:
number
;
private
_skipTerminalCommands
:
string
[];
private
_skipTerminalCommands
:
string
[];
private
_title
:
string
;
private
_title
:
string
;
private
_toDispose
:
lifecycle
.
IDisposable
[];
private
_instanceDisposables
:
lifecycle
.
IDisposable
[];
private
_processDisposables
:
lifecycle
.
IDisposable
[];
private
_wrapperElement
:
HTMLDivElement
;
private
_wrapperElement
:
HTMLDivElement
;
private
_xterm
:
any
;
private
_xterm
:
any
;
private
_xtermElement
:
HTMLDivElement
;
private
_xtermElement
:
HTMLDivElement
;
...
@@ -71,7 +72,8 @@ export class TerminalInstance implements ITerminalInstance {
...
@@ -71,7 +72,8 @@ export class TerminalInstance implements ITerminalInstance {
@
IPanelService
private
_panelService
:
IPanelService
,
@
IPanelService
private
_panelService
:
IPanelService
,
@
IWorkspaceContextService
private
_contextService
:
IWorkspaceContextService
@
IWorkspaceContextService
private
_contextService
:
IWorkspaceContextService
)
{
)
{
this
.
_toDispose
=
[];
this
.
_instanceDisposables
=
[];
this
.
_processDisposables
=
[];
this
.
_skipTerminalCommands
=
[];
this
.
_skipTerminalCommands
=
[];
this
.
_isExiting
=
false
;
this
.
_isExiting
=
false
;
this
.
_hadFocusOnExit
=
false
;
this
.
_hadFocusOnExit
=
false
;
...
@@ -92,7 +94,7 @@ export class TerminalInstance implements ITerminalInstance {
...
@@ -92,7 +94,7 @@ export class TerminalInstance implements ITerminalInstance {
}
}
public
addDisposable
(
disposable
:
lifecycle
.
IDisposable
):
void
{
public
addDisposable
(
disposable
:
lifecycle
.
IDisposable
):
void
{
this
.
_
toDispose
.
push
(
disposable
);
this
.
_
instanceDisposables
.
push
(
disposable
);
}
}
public
attachToElement
(
container
:
HTMLElement
):
void
{
public
attachToElement
(
container
:
HTMLElement
):
void
{
...
@@ -112,10 +114,12 @@ export class TerminalInstance implements ITerminalInstance {
...
@@ -112,10 +114,12 @@ export class TerminalInstance implements ITerminalInstance {
this
.
_process
.
on
(
'
message
'
,
(
message
)
=>
this
.
_sendPtyDataToXterm
(
message
));
this
.
_process
.
on
(
'
message
'
,
(
message
)
=>
this
.
_sendPtyDataToXterm
(
message
));
this
.
_xterm
.
on
(
'
data
'
,
(
data
)
=>
{
this
.
_xterm
.
on
(
'
data
'
,
(
data
)
=>
{
this
.
_process
.
send
({
if
(
this
.
_process
)
{
event
:
'
input
'
,
this
.
_process
.
send
({
data
:
this
.
_sanitizeInput
(
data
)
event
:
'
input
'
,
});
data
:
this
.
_sanitizeInput
(
data
)
});
}
return
false
;
return
false
;
});
});
this
.
_xterm
.
attachCustomKeydownHandler
((
event
:
KeyboardEvent
)
=>
{
this
.
_xterm
.
attachCustomKeydownHandler
((
event
:
KeyboardEvent
)
=>
{
...
@@ -139,48 +143,48 @@ export class TerminalInstance implements ITerminalInstance {
...
@@ -139,48 +143,48 @@ export class TerminalInstance implements ITerminalInstance {
return
false
;
return
false
;
}
}
});
});
(
<
HTMLElement
>
this
.
_xterm
.
element
).
addEventListener
(
'
mouseup
'
,
event
=>
{
this
.
_instanceDisposables
.
push
(
DOM
.
addDisposableListener
(
this
.
_xterm
.
element
,
'
mouseup
'
,
(
event
:
KeyboardEvent
)
=>
{
// Wait until mouseup has propogated through the DOM before evaluating the new selection
// Wait until mouseup has propogated through the DOM before evaluating the new selection
// state.
// state.
setTimeout
(()
=>
{
setTimeout
(()
=>
{
this
.
_refreshSelectionContextKey
();
this
.
_refreshSelectionContextKey
();
},
0
);
},
0
);
});
})
)
;
// xterm.js currently drops selection on keyup as we need to handle this case.
// xterm.js currently drops selection on keyup as we need to handle this case.
(
<
HTMLElement
>
this
.
_xterm
.
element
).
addEventListener
(
'
keyup
'
,
event
=>
{
this
.
_instanceDisposables
.
push
(
DOM
.
addDisposableListener
(
this
.
_xterm
.
element
,
'
keyup
'
,
(
event
:
KeyboardEvent
)
=>
{
// Wait until keyup has propogated through the DOM before evaluating the new selection
// Wait until keyup has propogated through the DOM before evaluating the new selection
// state.
// state.
setTimeout
(()
=>
{
setTimeout
(()
=>
{
this
.
_refreshSelectionContextKey
();
this
.
_refreshSelectionContextKey
();
},
0
);
},
0
);
});
})
)
;
const
xtermHelper
:
HTMLElement
=
this
.
_xterm
.
element
.
querySelector
(
'
.xterm-helpers
'
);
const
xtermHelper
:
HTMLElement
=
this
.
_xterm
.
element
.
querySelector
(
'
.xterm-helpers
'
);
const
focusTrap
:
HTMLElement
=
document
.
createElement
(
'
div
'
);
const
focusTrap
:
HTMLElement
=
document
.
createElement
(
'
div
'
);
focusTrap
.
setAttribute
(
'
tabindex
'
,
'
0
'
);
focusTrap
.
setAttribute
(
'
tabindex
'
,
'
0
'
);
DOM
.
addClass
(
focusTrap
,
'
focus-trap
'
);
DOM
.
addClass
(
focusTrap
,
'
focus-trap
'
);
focusTrap
.
addEventListener
(
'
focus
'
,
function
(
event
:
FocusEvent
)
{
this
.
_instanceDisposables
.
push
(
DOM
.
addDisposableListener
(
focusTrap
,
'
focus
'
,
(
event
:
FocusEvent
)
=>
{
let
currentElement
=
focusTrap
;
let
currentElement
=
focusTrap
;
while
(
!
DOM
.
hasClass
(
currentElement
,
'
part
'
))
{
while
(
!
DOM
.
hasClass
(
currentElement
,
'
part
'
))
{
currentElement
=
currentElement
.
parentElement
;
currentElement
=
currentElement
.
parentElement
;
}
}
const
hidePanelElement
=
<
HTMLElement
>
currentElement
.
querySelector
(
'
.hide-panel-action
'
);
const
hidePanelElement
=
<
HTMLElement
>
currentElement
.
querySelector
(
'
.hide-panel-action
'
);
hidePanelElement
.
focus
();
hidePanelElement
.
focus
();
});
})
)
;
xtermHelper
.
insertBefore
(
focusTrap
,
this
.
_xterm
.
textarea
);
xtermHelper
.
insertBefore
(
focusTrap
,
this
.
_xterm
.
textarea
);
this
.
_
toDispose
.
push
(
DOM
.
addDisposableListener
(
this
.
_xterm
.
textarea
,
'
focus
'
,
(
event
:
KeyboardEvent
)
=>
{
this
.
_
instanceDisposables
.
push
(
DOM
.
addDisposableListener
(
this
.
_xterm
.
textarea
,
'
focus
'
,
(
event
:
KeyboardEvent
)
=>
{
this
.
_terminalFocusContextKey
.
set
(
true
);
this
.
_terminalFocusContextKey
.
set
(
true
);
}));
}));
this
.
_
toDispose
.
push
(
DOM
.
addDisposableListener
(
this
.
_xterm
.
textarea
,
'
blur
'
,
(
event
:
KeyboardEvent
)
=>
{
this
.
_
instanceDisposables
.
push
(
DOM
.
addDisposableListener
(
this
.
_xterm
.
textarea
,
'
blur
'
,
(
event
:
KeyboardEvent
)
=>
{
this
.
_terminalFocusContextKey
.
reset
();
this
.
_terminalFocusContextKey
.
reset
();
this
.
_refreshSelectionContextKey
();
this
.
_refreshSelectionContextKey
();
}));
}));
this
.
_
toDispose
.
push
(
DOM
.
addDisposableListener
(
this
.
_xterm
.
element
,
'
focus
'
,
(
event
:
KeyboardEvent
)
=>
{
this
.
_
instanceDisposables
.
push
(
DOM
.
addDisposableListener
(
this
.
_xterm
.
element
,
'
focus
'
,
(
event
:
KeyboardEvent
)
=>
{
this
.
_terminalFocusContextKey
.
set
(
true
);
this
.
_terminalFocusContextKey
.
set
(
true
);
}));
}));
this
.
_
toDispose
.
push
(
DOM
.
addDisposableListener
(
this
.
_xterm
.
element
,
'
blur
'
,
(
event
:
KeyboardEvent
)
=>
{
this
.
_
instanceDisposables
.
push
(
DOM
.
addDisposableListener
(
this
.
_xterm
.
element
,
'
blur
'
,
(
event
:
KeyboardEvent
)
=>
{
this
.
_terminalFocusContextKey
.
reset
();
this
.
_terminalFocusContextKey
.
reset
();
this
.
_refreshSelectionContextKey
();
this
.
_refreshSelectionContextKey
();
}));
}));
...
@@ -231,7 +235,8 @@ export class TerminalInstance implements ITerminalInstance {
...
@@ -231,7 +235,8 @@ export class TerminalInstance implements ITerminalInstance {
this
.
_process
=
null
;
this
.
_process
=
null
;
}
}
this
.
_onDisposed
.
fire
(
this
);
this
.
_onDisposed
.
fire
(
this
);
this
.
_toDispose
=
lifecycle
.
dispose
(
this
.
_toDispose
);
this
.
_processDisposables
=
lifecycle
.
dispose
(
this
.
_processDisposables
);
this
.
_instanceDisposables
=
lifecycle
.
dispose
(
this
.
_instanceDisposables
);
}
}
public
focus
(
force
?:
boolean
):
void
{
public
focus
(
force
?:
boolean
):
void
{
...
@@ -396,9 +401,9 @@ export class TerminalInstance implements ITerminalInstance {
...
@@ -396,9 +401,9 @@ export class TerminalInstance implements ITerminalInstance {
this
.
_xterm
.
writeln
(
nls
.
localize
(
'
terminal.integrated.waitOnExit
'
,
'
Press any key to close the terminal
'
));
this
.
_xterm
.
writeln
(
nls
.
localize
(
'
terminal.integrated.waitOnExit
'
,
'
Press any key to close the terminal
'
));
// Disable all input if the terminal is exiting and listen for next keypress
// Disable all input if the terminal is exiting and listen for next keypress
this
.
_xterm
.
setOption
(
'
disableStdin
'
,
true
);
this
.
_xterm
.
setOption
(
'
disableStdin
'
,
true
);
(
<
HTMLElement
>
this
.
_xterm
.
textarea
).
addEventListener
(
'
keypress
'
,
(
data
)
=>
{
this
.
_processDisposables
.
push
(
DOM
.
addDisposableListener
(
this
.
_xterm
.
textarea
,
'
keypress
'
,
(
)
=>
{
this
.
dispose
();
this
.
dispose
();
});
})
)
;
}
else
{
}
else
{
this
.
dispose
();
this
.
dispose
();
if
(
exitCode
)
{
if
(
exitCode
)
{
...
@@ -420,7 +425,8 @@ export class TerminalInstance implements ITerminalInstance {
...
@@ -420,7 +425,8 @@ export class TerminalInstance implements ITerminalInstance {
}
}
}
}
public
reuseTerminal
(
shell
:
IShellLaunchConfig
):
void
{
public
reuseTerminal
(
shell
?:
IShellLaunchConfig
):
void
{
// Kill and clean up old process
if
(
this
.
_process
)
{
if
(
this
.
_process
)
{
this
.
_process
.
removeAllListeners
(
'
exit
'
);
this
.
_process
.
removeAllListeners
(
'
exit
'
);
if
(
this
.
_process
.
connected
)
{
if
(
this
.
_process
.
connected
)
{
...
@@ -428,14 +434,22 @@ export class TerminalInstance implements ITerminalInstance {
...
@@ -428,14 +434,22 @@ export class TerminalInstance implements ITerminalInstance {
}
}
this
.
_process
=
null
;
this
.
_process
=
null
;
}
}
lifecycle
.
dispose
(
this
.
_processDisposables
);
this
.
_processDisposables
=
[];
// Ensure new processes' output starts at start of new line
// Ensure new processes' output starts at start of new line
this
.
_xterm
.
write
(
'
\n\
x1b[G
'
);
this
.
_xterm
.
write
(
'
\n\
x1b[G
'
);
// Initialize new process
this
.
_createProcess
(
this
.
_contextService
.
getWorkspace
(),
shell
.
name
,
shell
);
this
.
_createProcess
(
this
.
_contextService
.
getWorkspace
(),
shell
.
name
,
shell
);
this
.
_process
.
on
(
'
message
'
,
(
message
)
=>
this
.
_sendPtyDataToXterm
(
message
));
this
.
_process
.
on
(
'
message
'
,
(
message
)
=>
this
.
_sendPtyDataToXterm
(
message
));
// TODO: Get rid of wait for any key listeners and any other listeners that are no longer valid
// Clean up waitOnExit state
if
(
this
.
_isExiting
&&
this
.
_shellLaunchConfig
.
waitOnExit
)
{
if
(
this
.
_isExiting
&&
this
.
_shellLaunchConfig
.
waitOnExit
)
{
this
.
_xterm
.
setOption
(
'
disableStdin
'
,
false
);
this
.
_xterm
.
setOption
(
'
disableStdin
'
,
false
);
this
.
_isExiting
=
false
;
}
}
// Set the new shell launch config
// Set the new shell launch config
this
.
_shellLaunchConfig
=
shell
;
this
.
_shellLaunchConfig
=
shell
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录