Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
myhjmzy
code-server
提交
bef46391
C
code-server
项目概览
myhjmzy
/
code-server
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
code-server
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
bef46391
编写于
1月 30, 2019
作者:
A
Asher
提交者:
Kyle Carberry
2月 05, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enable native clipboard for editor and inputs
StackOverflow will be useful again.
上级
ebe5e1b1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
160 addition
and
11 deletion
+160
-11
packages/ide/src/client.ts
packages/ide/src/client.ts
+2
-2
packages/ide/src/fill/clipboard.ts
packages/ide/src/fill/clipboard.ts
+24
-0
packages/vscode/src/client.ts
packages/vscode/src/client.ts
+52
-9
scripts/vscode.patch
scripts/vscode.patch
+82
-0
未找到文件。
packages/ide/src/client.ts
浏览文件 @
bef46391
...
...
@@ -4,7 +4,7 @@ import { InitData, ISharedProcessData } from "@coder/protocol";
import
{
retry
}
from
"
./retry
"
;
import
{
Upload
}
from
"
./upload
"
;
import
{
client
}
from
"
./fill/client
"
;
import
{
Clipboard
,
clipboard
}
from
"
./fill/clipboard
"
;
import
{
clipboard
}
from
"
./fill/clipboard
"
;
import
{
INotificationService
,
NotificationService
,
IProgressService
,
ProgressService
}
from
"
./fill/notification
"
;
import
{
IURIFactory
}
from
"
./fill/uri
"
;
...
...
@@ -19,7 +19,7 @@ import { IURIFactory } from "./fill/uri";
export
abstract
class
Client
{
public
readonly
retry
=
retry
;
public
readonly
clipboard
:
Clipboard
=
clipboard
;
public
readonly
clipboard
=
clipboard
;
public
readonly
uriFactory
:
IURIFactory
;
public
readonly
upload
=
new
Upload
(
new
NotificationService
(),
new
ProgressService
());
private
start
:
Time
|
undefined
;
...
...
packages/ide/src/fill/clipboard.ts
浏览文件 @
bef46391
...
...
@@ -36,6 +36,30 @@ export class Clipboard {
}
}
/**
* Paste currently copied text.
*/
public
async
paste
():
Promise
<
boolean
>
{
if
(
this
.
isEnabled
)
{
try
{
const
element
=
document
.
activeElement
as
HTMLInputElement
|
HTMLTextAreaElement
;
const
start
=
element
.
selectionStart
||
0
;
const
end
=
element
.
selectionEnd
;
const
allText
=
element
.
value
;
const
newText
=
allText
.
substring
(
0
,
start
)
+
(
await
this
.
readText
())
+
allText
.
substring
(
end
||
start
);
element
.
value
=
newText
;
return
true
;
}
catch
(
ex
)
{
// Will try execCommand below.
}
}
return
document
.
execCommand
(
"
paste
"
);
}
/**
* Return true if the native clipboard is supported.
*/
...
...
packages/vscode/src/client.ts
浏览文件 @
bef46391
...
...
@@ -9,7 +9,6 @@ import "./vscode.scss";
import
{
Client
as
IDEClient
,
IURI
,
IURIFactory
,
IProgress
,
INotificationHandle
}
from
"
@coder/ide
"
;
import
{
registerContextMenuListener
}
from
"
vs/base/parts/contextmenu/electron-main/contextmenu
"
;
import
{
LogLevel
}
from
"
vs/platform/log/common/log
"
;
// import { RawContextKey, IContextKeyService } from "vs/platform/contextkey/common/contextkey";
import
{
URI
}
from
"
vs/base/common/uri
"
;
import
{
INotificationService
}
from
"
vs/platform/notification/common/notification
"
;
import
{
IProgressService2
,
ProgressLocation
}
from
"
vs/platform/progress/common/progress
"
;
...
...
@@ -19,11 +18,15 @@ import { IEditorService, IResourceEditor } from "vs/workbench/services/editor/co
import
{
IEditorGroup
}
from
"
vs/workbench/services/group/common/editorGroupsService
"
;
import
{
IWindowsService
}
from
"
vs/platform/windows/common/windows
"
;
import
{
ServiceCollection
}
from
"
vs/platform/instantiation/common/serviceCollection
"
;
import
{
RawContextKey
,
IContextKeyService
}
from
"
vs/platform/contextkey/common/contextkey
"
;
import
{
Action
}
from
"
vs/base/common/actions
"
;
import
*
as
nls
from
"
vs/nls
"
;
export
class
Client
extends
IDEClient
{
private
readonly
windowId
=
parseInt
(
new
Date
().
toISOString
().
replace
(
/
[
-:.TZ
]
/g
,
""
),
10
);
private
_serviceCollection
:
ServiceCollection
|
undefined
;
private
_clipboardContextKey
:
RawContextKey
<
boolean
>
|
undefined
;
public
async
handleExternalDrop
(
target
:
ExplorerItem
|
Model
,
originalEvent
:
DragMouseEvent
):
Promise
<
void
>
{
await
this
.
upload
.
uploadDropped
(
...
...
@@ -57,6 +60,47 @@ export class Client extends IDEClient {
});
}
/**
* Use to toggle the paste option inside editors based on the native clipboard.
*/
public
get
clipboardContextKey
():
RawContextKey
<
boolean
>
{
if
(
!
this
.
_clipboardContextKey
)
{
throw
new
Error
(
"
Trying to access clipboard context key before it has been set
"
);
}
return
this
.
_clipboardContextKey
;
}
public
get
clipboardText
():
Promise
<
string
>
{
return
this
.
clipboard
.
readText
();
}
/**
* Create a paste action for use in text inputs.
*/
public
get
pasteAction
():
Action
{
const
getLabel
=
(
enabled
:
boolean
):
string
=>
{
return
enabled
?
nls
.
localize
(
"
paste
"
,
"
Paste
"
)
:
nls
.
localize
(
"
pasteWithKeybind
"
,
"
Paste (must use keybind)
"
);
};
const
pasteAction
=
new
Action
(
"
editor.action.clipboardPasteAction
"
,
getLabel
(
this
.
clipboard
.
isEnabled
),
undefined
,
this
.
clipboard
.
isEnabled
,
async
():
Promise
<
boolean
>
=>
this
.
clipboard
.
paste
(),
);
this
.
clipboard
.
onPermissionChange
((
enabled
)
=>
{
pasteAction
.
label
=
getLabel
(
enabled
);
pasteAction
.
enabled
=
enabled
;
});
return
pasteAction
;
}
public
get
serviceCollection
():
ServiceCollection
{
if
(
!
this
.
_serviceCollection
)
{
throw
new
Error
(
"
Trying to access service collection before it has been set
"
);
...
...
@@ -134,6 +178,8 @@ export class Client extends IDEClient {
process
.
env
.
VSCODE_LOGS
=
data
.
logPath
;
});
this
.
_clipboardContextKey
=
new
RawContextKey
(
"
nativeClipboard
"
,
this
.
clipboard
.
isEnabled
);
return
this
.
task
(
"
Start workbench
"
,
1000
,
async
(
data
)
=>
{
paths
.
_paths
.
appData
=
data
.
dataDirectory
;
paths
.
_paths
.
defaultUserData
=
data
.
dataDirectory
;
...
...
@@ -154,14 +200,11 @@ export class Client extends IDEClient {
folderUri
:
URI
.
file
(
data
.
workingDirectory
),
});
// TODO: Set up clipboard context.
// const workbench = workbenchShell.workbench;
// const contextKeys = workbench.workbenchParams.serviceCollection.get(IContextKeyService) as IContextKeyService;
// const clipboardContextKey = new RawContextKey("nativeClipboard", this.clipboard.isSupported);
// const bounded = clipboardContextKey.bindTo(contextKeys);
// this.clipboard.onPermissionChange((enabled) => {
// bounded.set(enabled);
// });
const
contextKeys
=
this
.
serviceCollection
.
get
(
IContextKeyService
)
as
IContextKeyService
;
const
bounded
=
this
.
clipboardContextKey
.
bindTo
(
contextKeys
);
this
.
clipboard
.
onPermissionChange
((
enabled
)
=>
{
bounded
.
set
(
enabled
);
});
this
.
clipboard
.
initialize
();
},
this
.
initData
,
pathSets
);
}
...
...
scripts/vscode.patch
浏览文件 @
bef46391
...
...
@@ -8,6 +8,67 @@ index 457818a975..ad45ffe58a 100644
}
+
+startup({ machineId: "1" });
diff --git a/src/vs/editor/contrib/clipboard/clipboard.ts b/src/vs/editor/contrib/clipboard/clipboard.ts
index 5e43f1b39e..7775e3b6da 100644
--- a/src/vs/editor/contrib/clipboard/clipboard.ts
+++ b/src/vs/editor/contrib/clipboard/clipboard.ts
@@ -16,6 +16,10 @@
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { MenuId } from 'vs/platform/actions/common/actions';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
+import { CodeEditorWidget } from "vs/editor/browser/widget/codeEditorWidget";
+import { Handler } from "vs/editor/common/editorCommon";
+import { ContextKeyExpr } from "vs/platform/contextkey/common/contextkey";
+import { client } from "../../../../../../../packages/vscode";
const CLIPBOARD_CONTEXT_MENU_GROUP = '9_cutcopypaste';
@@ -26,7 +30,8 @@
const supportsCopyWithSyntaxHighlighting = (supportsCopy && !browser.isEdgeOrIE)
// Chrome incorrectly returns true for document.queryCommandSupported('paste')
// when the paste feature is available but the calling script has insufficient
// privileges to actually perform the action
-const supportsPaste = (platform.isNative || (!browser.isChrome && document.queryCommandSupported('paste')));
+// const supportsPaste = (platform.isNative || (!browser.isChrome && document.queryCommandSupported('paste')));
+const supportsPaste = true;
type ExecCommand = 'cut' | 'copy' | 'paste';
@@ -178,7 +183,7 @@
class ExecCommandPasteAction extends ExecCommandAction {
id: 'editor.action.clipboardPasteAction',
label: nls.localize('actions.clipboard.pasteLabel', "Paste"),
alias: 'Paste',
- precondition: EditorContextKeys.writable,
+ precondition: ContextKeyExpr.and(EditorContextKeys.writable, client.clipboardContextKey),
kbOpts: kbOpts,
menuOpts: {
group: CLIPBOARD_CONTEXT_MENU_GROUP,
@@ -188,10 +193,25 @@
class ExecCommandPasteAction extends ExecCommandAction {
menuId: MenuId.MenubarEditMenu,
group: '2_ccp',
title: nls.localize({ key: 'miPaste', comment: ['&& denotes a mnemonic'] }, "&&Paste"),
- order: 3
+ order: 3,
+ when: client.clipboardContextKey,
}
});
}
+
+ public async run(accessor, editor: ICodeEditor): Promise<void> {
+ if (editor instanceof CodeEditorWidget) {
+ try {
+ editor.trigger('', Handler.Paste, {
+ text: await client.clipboardText,
+ });
+ } catch (ex) {
+ super.run(accessor, editor);
+ }
+ } else {
+ super.run(accessor, editor);
+ }
+ }
}
class ExecCommandCopyWithSyntaxHighlightingAction extends ExecCommandAction {
diff --git a/src/vs/loader.js b/src/vs/loader.js
index 2bf7fe37d7..81cc668f12 100644
--- a/src/vs/loader.js
...
...
@@ -94,6 +155,27 @@ index a43d63aa51..4c6df2fcd9 100644
});
});
});
diff --git a/src/vs/workbench/electron-browser/window.ts b/src/vs/workbench/electron-browser/window.ts
index ea348f3a04..7c943a71c2 100644
--- a/src/vs/workbench/electron-browser/window.ts
+++ b/src/vs/workbench/electron-browser/window.ts
@@ -38,6 +38,7 @@
import { AccessibilitySupport, isRootUser, isWindows, isMacintosh } from 'vs/bas
import product from 'vs/platform/node/product';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { EditorServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
+import { client } from "../../../../../../packages/vscode";
const TextInputActions: IAction[] = [
new Action('undo', nls.localize('undo', "Undo"), null, true, () => document.execCommand('undo') && Promise.resolve(true)),
@@ -45,7 +46,7 @@
const TextInputActions: IAction[] = [
new Separator(),
new Action('editor.action.clipboardCutAction', nls.localize('cut', "Cut"), null, true, () => document.execCommand('cut') && Promise.resolve(true)),
new Action('editor.action.clipboardCopyAction', nls.localize('copy', "Copy"), null, true, () => document.execCommand('copy') && Promise.resolve(true)),
- new Action('editor.action.clipboardPasteAction', nls.localize('paste', "Paste"), null, true, () => document.execCommand('paste') && Promise.resolve(true)),
+ client.pasteAction,
new Separator(),
new Action('editor.action.selectAll', nls.localize('selectAll', "Select All"), null, true, () => document.execCommand('selectAll') && Promise.resolve(true))
];
diff --git a/src/vs/workbench/electron-browser/workbench.ts b/src/vs/workbench/electron-browser/workbench.ts
index 35bc4a82b3..9cc84bdf28 100644
--- a/src/vs/workbench/electron-browser/workbench.ts
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录