Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
dbe26fa7
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,发现更多精彩内容 >>
提交
dbe26fa7
编写于
7月 19, 2017
作者:
P
Peng Lyu
提交者:
GitHub
7月 19, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #30021 from mihailik/master
Ctrl-T to use word under cursor or current selection
上级
277d295b
e522f5f7
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
144 addition
and
19 deletion
+144
-19
src/vs/editor/contrib/find/common/find.ts
src/vs/editor/contrib/find/common/find.ts
+25
-0
src/vs/editor/contrib/find/common/findController.ts
src/vs/editor/contrib/find/common/findController.ts
+2
-14
src/vs/editor/contrib/find/test/common/find.test.ts
src/vs/editor/contrib/find/test/common/find.test.ts
+89
-0
src/vs/workbench/parts/search/browser/search.contribution.ts
src/vs/workbench/parts/search/browser/search.contribution.ts
+28
-5
未找到文件。
src/vs/editor/contrib/find/common/find.ts
0 → 100644
浏览文件 @
dbe26fa7
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
export
function
getSelectionSearchString
(
editor
:
editorCommon
.
ICommonCodeEditor
):
string
{
let
selection
=
editor
.
getSelection
();
// if selection spans multiple lines, default search string to empty
if
(
selection
.
startLineNumber
===
selection
.
endLineNumber
)
{
if
(
selection
.
isEmpty
())
{
let
wordAtPosition
=
editor
.
getModel
().
getWordAtPosition
(
selection
.
getStartPosition
());
if
(
wordAtPosition
)
{
return
wordAtPosition
.
word
;
}
}
else
{
return
editor
.
getModel
().
getValueInRange
(
selection
);
}
}
return
null
;
}
src/vs/editor/contrib/find/common/findController.ts
浏览文件 @
dbe26fa7
...
...
@@ -16,6 +16,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import
{
editorAction
,
commonEditorContribution
,
ServicesAccessor
,
EditorAction
,
EditorCommand
,
CommonEditorRegistry
}
from
'
vs/editor/common/editorCommonExtensions
'
;
import
{
FIND_IDS
,
FindModelBoundToEditorModel
,
ToggleCaseSensitiveKeybinding
,
ToggleRegexKeybinding
,
ToggleWholeWordKeybinding
,
ToggleSearchScopeKeybinding
,
ShowPreviousFindTermKeybinding
,
ShowNextFindTermKeybinding
}
from
'
vs/editor/contrib/find/common/findModel
'
;
import
{
FindReplaceState
,
FindReplaceStateChangedEvent
,
INewFindReplaceState
}
from
'
vs/editor/contrib/find/common/findState
'
;
import
{
getSelectionSearchString
}
from
'
vs/editor/contrib/find/common/find
'
;
import
{
DocumentHighlightProviderRegistry
}
from
'
vs/editor/common/modes
'
;
import
{
RunOnceScheduler
,
Delayer
}
from
'
vs/base/common/async
'
;
import
{
CursorChangeReason
,
ICursorSelectionChangedEvent
}
from
'
vs/editor/common/controller/cursorEvents
'
;
...
...
@@ -206,20 +207,7 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
}
public
getSelectionSearchString
():
string
{
let
selection
=
this
.
_editor
.
getSelection
();
if
(
selection
.
startLineNumber
===
selection
.
endLineNumber
)
{
if
(
selection
.
isEmpty
())
{
let
wordAtPosition
=
this
.
_editor
.
getModel
().
getWordAtPosition
(
selection
.
getStartPosition
());
if
(
wordAtPosition
)
{
return
wordAtPosition
.
word
;
}
}
else
{
return
this
.
_editor
.
getModel
().
getValueInRange
(
selection
);
}
}
return
null
;
return
getSelectionSearchString
(
this
.
_editor
);
}
protected
_start
(
opts
:
IFindStartOptions
):
void
{
...
...
src/vs/editor/contrib/find/test/common/find.test.ts
0 → 100644
浏览文件 @
dbe26fa7
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
getSelectionSearchString
}
from
'
vs/editor/contrib/find/common/find
'
;
import
{
withMockCodeEditor
}
from
'
vs/editor/test/common/mocks/mockCodeEditor
'
;
suite
(
'
Find
'
,
()
=>
{
test
(
'
search string at position
'
,
()
=>
{
withMockCodeEditor
([
'
ABC DEF
'
,
'
0123 456
'
],
{},
(
editor
,
cursor
)
=>
{
// The cursor is at the very top, of the file, at the first ABC
let
searchStringAtTop
=
getSelectionSearchString
(
editor
);
assert
.
equal
(
searchStringAtTop
,
'
ABC
'
);
// Move cursor to the end of ABC
editor
.
setPosition
(
new
Position
(
1
,
3
));
let
searchStringAfterABC
=
getSelectionSearchString
(
editor
);
assert
.
equal
(
searchStringAfterABC
,
'
ABC
'
);
// Move cursor to DEF
editor
.
setPosition
(
new
Position
(
1
,
5
));
let
searchStringInsideDEF
=
getSelectionSearchString
(
editor
);
assert
.
equal
(
searchStringInsideDEF
,
'
DEF
'
);
});
});
test
(
'
search string with selection
'
,
()
=>
{
withMockCodeEditor
([
'
ABC DEF
'
,
'
0123 456
'
],
{},
(
editor
,
cursor
)
=>
{
// Select A of ABC
editor
.
setSelection
(
new
Range
(
1
,
1
,
1
,
2
));
let
searchStringSelectionA
=
getSelectionSearchString
(
editor
);
assert
.
equal
(
searchStringSelectionA
,
'
A
'
);
// Select BC of ABC
editor
.
setSelection
(
new
Range
(
1
,
2
,
1
,
4
));
let
searchStringSelectionBC
=
getSelectionSearchString
(
editor
);
assert
.
equal
(
searchStringSelectionBC
,
'
BC
'
);
// Select BC DE
editor
.
setSelection
(
new
Range
(
1
,
2
,
1
,
7
));
let
searchStringSelectionBCDE
=
getSelectionSearchString
(
editor
);
assert
.
equal
(
searchStringSelectionBCDE
,
'
BC DE
'
);
});
});
test
(
'
search string with multiline selection
'
,
()
=>
{
withMockCodeEditor
([
'
ABC DEF
'
,
'
0123 456
'
],
{},
(
editor
,
cursor
)
=>
{
// Select first line and newline
editor
.
setSelection
(
new
Range
(
1
,
1
,
2
,
1
));
let
searchStringSelectionWholeLine
=
getSelectionSearchString
(
editor
);
assert
.
equal
(
searchStringSelectionWholeLine
,
null
);
// Select first line and chunk of second
editor
.
setSelection
(
new
Range
(
1
,
1
,
2
,
4
));
let
searchStringSelectionTwoLines
=
getSelectionSearchString
(
editor
);
assert
.
equal
(
searchStringSelectionTwoLines
,
null
);
// Select end of first line newline and and chunk of second
editor
.
setSelection
(
new
Range
(
1
,
7
,
2
,
4
));
let
searchStringSelectionSpanLines
=
getSelectionSearchString
(
editor
);
assert
.
equal
(
searchStringSelectionSpanLines
,
null
);
});
});
});
\ No newline at end of file
src/vs/workbench/parts/search/browser/search.contribution.ts
浏览文件 @
dbe26fa7
...
...
@@ -11,17 +11,20 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import
{
ViewletRegistry
,
Extensions
as
ViewletExtensions
,
ViewletDescriptor
}
from
'
vs/workbench/browser/viewlet
'
;
import
{
IConfigurationRegistry
,
Extensions
as
ConfigurationExtensions
,
ConfigurationScope
}
from
'
vs/platform/configuration/common/configurationRegistry
'
;
import
nls
=
require
(
'
vs/nls
'
);
import
{
IAction
}
from
'
vs/base/common/actions
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IAction
,
Action
}
from
'
vs/base/common/actions
'
;
import
{
explorerItemToFileResource
}
from
'
vs/workbench/parts/files/common/files
'
;
import
{
SyncActionDescriptor
}
from
'
vs/platform/actions/common/actions
'
;
import
{
Separator
}
from
'
vs/base/browser/ui/actionbar/actionbar
'
;
import
{
Scope
,
IActionBarRegistry
,
Extensions
as
ActionBarExtensions
,
ActionBarContributor
}
from
'
vs/workbench/browser/actions
'
;
import
{
IWorkbenchActionRegistry
,
Extensions
as
ActionExtensions
}
from
'
vs/workbench/common/actionRegistry
'
;
import
{
QuickOpenHandlerDescriptor
,
IQuickOpenRegistry
,
Extensions
as
QuickOpenExtensions
,
QuickOpenAction
}
from
'
vs/workbench/browser/quickopen
'
;
import
{
QuickOpenHandlerDescriptor
,
IQuickOpenRegistry
,
Extensions
as
QuickOpenExtensions
}
from
'
vs/workbench/browser/quickopen
'
;
import
{
KeybindingsRegistry
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
IQuickOpenService
}
from
'
vs/platform/quickOpen/common/quickOpen
'
;
import
{
ICodeEditorService
}
from
'
vs/editor/common/services/codeEditorService
'
;
import
{
getSelectionSearchString
}
from
'
vs/editor/contrib/find/common/find
'
;
import
{
IViewletService
}
from
'
vs/workbench/services/viewlet/browser/viewlet
'
;
import
{
KeyMod
,
KeyCode
}
from
'
vs/base/common/keyCodes
'
;
import
{
ITree
}
from
'
vs/base/parts/tree/browser/tree
'
;
...
...
@@ -226,10 +229,30 @@ const ACTION_ID = 'workbench.action.showAllSymbols';
const
ACTION_LABEL
=
nls
.
localize
(
'
showTriggerActions
'
,
"
Go to Symbol in Workspace...
"
);
const
ALL_SYMBOLS_PREFIX
=
'
#
'
;
class
ShowAllSymbolsAction
extends
QuickOpen
Action
{
class
ShowAllSymbolsAction
extends
Action
{
constructor
(
actionId
:
string
,
actionLabel
:
string
,
@
IQuickOpenService
quickOpenService
:
IQuickOpenService
)
{
super
(
actionId
,
actionLabel
,
ALL_SYMBOLS_PREFIX
,
quickOpenService
);
constructor
(
actionId
:
string
,
actionLabel
:
string
,
@
IQuickOpenService
private
quickOpenService
:
IQuickOpenService
,
@
ICodeEditorService
private
editorService
:
ICodeEditorService
)
{
super
(
actionId
,
actionLabel
);
this
.
enabled
=
!!
this
.
quickOpenService
;
}
public
run
(
context
?:
any
):
TPromise
<
void
>
{
let
prefix
=
ALL_SYMBOLS_PREFIX
;
let
inputSelection
:
{
start
:
number
;
end
:
number
;
}
=
void
0
;
let
editor
=
this
.
editorService
.
getFocusedCodeEditor
();
const
word
=
editor
&&
getSelectionSearchString
(
editor
);
if
(
word
)
{
prefix
=
prefix
+
word
;
inputSelection
=
{
start
:
1
,
end
:
word
.
length
+
1
};
}
this
.
quickOpenService
.
show
(
prefix
,
{
inputSelection
});
return
TPromise
.
as
(
null
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录