提交 49b27148 编写于 作者: R rebornix

Update mouse pointer style while DND

上级 2cca80e5
......@@ -337,7 +337,7 @@ export class Configuration extends CommonEditorConfiguration {
super.dispose();
}
protected _getEditorClassName(theme: string, fontLigatures: boolean): string {
protected _getEditorClassName(theme: string, fontLigatures: boolean, mouseStyle: 'text' | 'default' | 'copy'): string {
let extra = '';
if (browser.isIE) {
extra += 'ie ';
......@@ -352,6 +352,11 @@ export class Configuration extends CommonEditorConfiguration {
if (fontLigatures) {
extra += 'enable-ligatures ';
}
if (mouseStyle === 'default') {
extra += 'mouse-default ';
} else if (mouseStyle === 'copy') {
extra += 'mouse-copy ';
}
return 'monaco-editor ' + extra + theme;
}
......
......@@ -536,7 +536,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed
private _computeInternalOptions(): editorCommon.InternalEditorOptions {
let opts = this._configWithDefaults.getEditorOptions();
let editorClassName = this._getEditorClassName(opts.theme, toBoolean(opts.fontLigatures));
let editorClassName = this._getEditorClassName(opts.theme, toBoolean(opts.fontLigatures), opts.mouseStyle);
let disableTranslate3d = toBoolean(opts.disableTranslate3d);
let canUseTranslate3d = this._getCanUseTranslate3d();
......@@ -587,7 +587,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed
return r ? r : 1;
}
protected abstract _getEditorClassName(theme: string, fontLigatures: boolean): string;
protected abstract _getEditorClassName(theme: string, fontLigatures: boolean, mouseDrag: 'text' | 'default' | 'copy'): string;
protected abstract getOuterWidth(): number;
......
......@@ -67,6 +67,7 @@ class ConfigClass implements IConfiguration {
cursorBlinking: 'blink',
mouseWheelZoom: false,
cursorStyle: 'line',
mouseStyle: 'text',
fontLigatures: false,
disableTranslate3d: false,
disableMonospaceOptimizations: false,
......
......@@ -309,6 +309,12 @@ export interface IEditorOptions {
* Defaults to false.
*/
mouseWheelZoom?: boolean;
/**
* Control the mouse pointer style, either 'text' or 'default' or 'copy'
* Defaults to 'text'
* @internal
*/
mouseStyle?: 'text' | 'default' | 'copy';
/**
* Control the cursor style, either 'block' or 'line'.
* Defaults to 'line'.
......
......@@ -14,4 +14,11 @@
.monaco-editor.hc-black .dnd-target {
border-right: 2px dotted #fff;
color: #000; /* opposite of #fff */
}
.monaco-editor.mouse-default .view-lines {
cursor: default;
}
.monaco-editor.mouse-copy .view-lines {
cursor: copy;
}
\ No newline at end of file
......@@ -6,7 +6,9 @@
'use strict';
import 'vs/css!./dnd';
import { IMouseEvent } from "vs/base/browser/mouseEvent";
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { isWindows } from 'vs/base/common/platform';
import { ICodeEditor, IEditorMouseEvent, IMouseTarget } from 'vs/editor/browser/editorBrowser';
import { editorContribution } from 'vs/editor/browser/editorBrowserExtensions';
import * as editorCommon from 'vs/editor/common/editorCommon';
......@@ -38,6 +40,18 @@ export class DragAndDropController implements editorCommon.IEditorContribution {
this._dragSelection = null;
}
private isDragAndCopy(mouseEvent: IMouseEvent) {
if (isWindows && mouseEvent.ctrlKey) {
return true;
}
if (!isWindows && mouseEvent.altKey) {
return true;
}
return false;
}
private _onEditorMouseDrag(mouseEvent: IEditorMouseEvent): void {
let target = mouseEvent.target;
......@@ -50,6 +64,16 @@ export class DragAndDropController implements editorCommon.IEditorContribution {
}
}
if (this.isDragAndCopy(mouseEvent.event)) {
this._editor.updateOptions({
mouseStyle: 'copy'
});
} else {
this._editor.updateOptions({
mouseStyle: 'default'
});
}
if (this._dragSelection.containsPosition(target.position)) {
this._removeDecoration();
} else {
......@@ -71,10 +95,14 @@ export class DragAndDropController implements editorCommon.IEditorContribution {
});
this._editor.setSelections(newSelections);
} else if (!this._dragSelection.containsPosition(newCursorPosition)) {
this._editor.executeCommand(DragAndDropController.ID, new DragAndDropCommand(this._dragSelection, newCursorPosition, mouseEvent.event.altKey));
this._editor.executeCommand(DragAndDropController.ID, new DragAndDropCommand(this._dragSelection, newCursorPosition, this.isDragAndCopy(mouseEvent.event)));
}
}
this._editor.updateOptions({
mouseStyle: 'text'
});
this._removeDecoration();
this._dragSelection = null;
}
......
......@@ -15,17 +15,17 @@ export class DragAndDropCommand implements editorCommon.ICommand {
private selection: Selection;
private targetPosition: Position;
private targetSelection: Selection;
private altKey: boolean;
private copy: boolean;
constructor(selection: Selection, targetPosition: Position, altKey: boolean) {
constructor(selection: Selection, targetPosition: Position, copy: boolean) {
this.selection = selection;
this.targetPosition = targetPosition;
this.altKey = altKey;
this.copy = copy;
}
public getEditOperations(model: editorCommon.ITokenizedModel, builder: editorCommon.IEditOperationBuilder): void {
let text = model.getValueInRange(this.selection);
if (!this.altKey) {
if (!this.copy) {
builder.addEditOperation(this.selection, null);
}
builder.addEditOperation(new Range(this.targetPosition.lineNumber, this.targetPosition.column, this.targetPosition.lineNumber, this.targetPosition.column), text);
......@@ -35,7 +35,7 @@ export class DragAndDropCommand implements editorCommon.ICommand {
return;
}
if (this.altKey) {
if (this.copy) {
this.targetSelection = new Selection(
this.targetPosition.lineNumber,
this.targetPosition.column,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册