Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add watermark for input box (#4117) #4124

Merged
merged 1 commit into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions news/1 Enhancements/4111.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Watermark for Python Interactive input prompt
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"DataScience.pythonVersionHeaderNoPyKernel": "Python version may not match, no ipykernel found:",
"DataScience.pythonRestartHeader": "Restarted Kernel:",
"DataScience.executingCodeFailure" : "Executing code failed : {0}",
"DataScience.inputWatermark" : "Shift-enter to run",
"Linter.InstalledButNotEnabled": "Linter {0} is installed but not enabled.",
"Linter.replaceWithSelectedLinter": "Multiple linters are enabled in settings. Replace with '{0}'?",
"DataScience.jupyterSelectURILaunchLocal": "Launch a local Jupyter server when needed",
Expand Down
1 change: 1 addition & 0 deletions src/client/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export namespace DataScience {
export const pythonInterruptFailedHeader = localize('DataScience.pythonInterruptFailedHeader', 'Keyboard interrupt crashed the kernel. Kernel restarted.');
export const sysInfoURILabel = localize('DataScience.sysInfoURILabel', 'Jupyter Server URI: ');
export const executingCodeFailure = localize('DataScience.executingCodeFailure', 'Executing code failed : {0}');
export const inputWatermark = localize('DataScience.inputWatermark', 'Shift-enter to run');
}

export namespace DebugConfigurationPrompts {
Expand Down
6 changes: 4 additions & 2 deletions src/datascience-ui/history-react/MainPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
super(props);

// Default state should show a busy message
this.state = { cellVMs: [], busy: true, undoStack: [], redoStack : [], historyStack: []};
this.state = { cellVMs: [], busy: true, undoStack: [], redoStack : [], historyStack: [], submittedText: false};

// Add test state if necessary
if (!this.props.skipDefault) {
Expand Down Expand Up @@ -213,6 +213,7 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
submitNewCode={this.submitInput}
baseTheme={this.props.baseTheme}
codeTheme={this.props.codeTheme}
showWatermark={!this.state.submittedText}
gotoCode={() => this.gotoCellCode(index)}
delete={() => this.deleteCell(index)}/>
</ErrorBoundary>
Expand Down Expand Up @@ -637,7 +638,8 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
undoStack : this.pushStack(this.state.undoStack, this.state.cellVMs),
redoStack: this.state.redoStack,
skipNextScroll: false,
historyStack: newHistory
historyStack: newHistory,
submittedText: true
});

// Send a message to execute this code if necessary.
Expand Down
2 changes: 2 additions & 0 deletions src/datascience-ui/history-react/cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface ICellProps {
autoFocus: boolean;
maxTextSize?: number;
history: string [];
showWatermark: boolean;
gotoCode(): void;
delete(): void;
submitNewCode(code: string): void;
Expand Down Expand Up @@ -204,6 +205,7 @@ export class Cell extends React.Component<ICellProps> {
codeTheme={this.props.codeTheme}
testMode={this.props.testMode ? true : false}
readOnly={!this.props.cellVM.editable}
showWatermark={this.props.showWatermark}
onSubmit={this.props.submitNewCode}
onChangeLineCount={this.onChangeLineCount}
ref={this.updateCodeRef}
Expand Down
14 changes: 14 additions & 0 deletions src/datascience-ui/history-react/code.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,17 @@
.code-area-editable {
margin-bottom: 10px;
}

.code-watermark {
position: absolute;
top: 0;
left: 30px;
z-index: 500;
font-style: italic;
color: var(--vscode-pickerGroup-border);
}

.hide {
visibility: hidden;
}

12 changes: 11 additions & 1 deletion src/datascience-ui/history-react/code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as RCM from 'react-codemirror';

import './code.css';

import { getLocString } from '../react-common/locReactSide';
import { Cursor } from './cursor';
import { InputHistory } from './inputHistory';

Expand All @@ -22,6 +23,7 @@ export interface ICodeProps {
readOnly: boolean;
history: string[];
cursorType: string;
showWatermark: boolean;
onSubmit(code: string): void;
onChangeLineCount(lineCount: number) : void;

Expand All @@ -33,6 +35,7 @@ interface ICodeState {
cursorTop: number;
cursorBottom: number;
charUnderCursor: string;
allowWatermark: boolean;
}

export class Code extends React.Component<ICodeProps, ICodeState> {
Expand All @@ -43,7 +46,7 @@ export class Code extends React.Component<ICodeProps, ICodeState> {

constructor(prop: ICodeProps) {
super(prop);
this.state = {focused: false, cursorLeft: 0, cursorTop: 0, cursorBottom: 0, charUnderCursor: ''};
this.state = {focused: false, cursorLeft: 0, cursorTop: 0, cursorBottom: 0, charUnderCursor: '', allowWatermark: true};
this.history = new InputHistory(this.props.history);
}

Expand All @@ -57,6 +60,7 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
public render() {
const readOnly = this.props.testMode || this.props.readOnly;
const classes = readOnly ? 'code-area' : 'code-area code-area-editable';
const waterMarkClass = this.props.showWatermark && this.state.allowWatermark && !readOnly ? 'code-watermark' : 'hide';
return (
<div className={classes}>
<Cursor
Expand Down Expand Up @@ -92,6 +96,7 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
onFocusChange={this.onFocusChange}
onCursorActivity={this.onCursorActivity}
/>
<div className={waterMarkClass}>{this.getWatermarkString()}</div>
</div>
);
}
Expand All @@ -104,6 +109,10 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
}
}

private getWatermarkString = () : string => {
return getLocString('DataScience.inputWatermark', 'Shift-enter to run');
}

private onCursorActivity = (codeMirror: CodeMirror.Editor) => {
// Update left/top/char for cursor
if (codeMirror) {
Expand Down Expand Up @@ -245,5 +254,6 @@ export class Code extends React.Component<ICodeProps, ICodeState> {

private onChange = (newValue: string, change: CodeMirror.EditorChange) => {
this.history.onChange();
this.setState({allowWatermark: false});
}
}
4 changes: 3 additions & 1 deletion src/datascience-ui/history-react/mainPanelState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface IMainPanelState {
undoStack : ICellViewModel[][];
redoStack : ICellViewModel[][];
historyStack: string[];
submittedText: boolean;
}

// This function generates test state when running under a browser instead of inside of
Expand All @@ -28,7 +29,8 @@ export function generateTestState(inputBlockToggled : (id: string) => void, file
skipNextScroll : false,
undoStack : [],
redoStack : [],
historyStack: []
historyStack: [],
submittedText: false
};
}

Expand Down