void HandleFocusEvent(EditorEvent evnt, CodeCellState sourceCodeCellState) { var sourceCell = ((CellEditorView)evnt.Source).Cell; if (focusedCellState == sourceCodeCellState && focusedWorkbookCell == sourceCell) { return; } focusedCellState = sourceCodeCellState; UpdateFocusedCellViewFooter(false); focusedWorkbookCell = sourceCell; UpdateFocusedCellViewFooter(true); }
protected override void BindCodeCellToView(CodeCell cell, CodeCellState codeCellState) { var codeCellView = new CodeCellView( codeCellState, cell, webView.Document, rendererContext); cell.View = codeCellView; codeCellState.Editor = codeCellView.Editor; codeCellState.View = codeCellView; codeCellView.Events.Subscribe(new Observer <IEvent> (HandleCodeCellViewEvent)); }
public async Task <bool> AddTopLevelReferencesAsync( IReadOnlyList <string> references, CancellationToken cancellationToken = default) { if (references == null || references.Count == 0) { return(false); } if (nugetReferenceCellState == null) { var firstCodeCellId = workspace .GetTopologicallySortedCellIds() .FirstOrDefault(); var nugetReferenceCellId = await InsertCodeCellAsync( string.Empty, firstCodeCellId, true, cancellationToken); nugetReferenceCellState = cellStates [nugetReferenceCellId]; } // TODO: Prevent dupes. Return false if no changes made var builder = new StringBuilder(nugetReferenceCellState.Buffer.Value); foreach (var reference in references) { if (builder.Length > 0) { //builder.AppendLine (); builder.Append("\n"); } builder .Append("#r \"") .Append(reference) .Append("\""); } nugetReferenceCellState.Buffer.Value = builder.ToString(); return(true); }
protected override CodeCellState StartNewCodeCell() => focusedCellState = base.StartNewCodeCell();
public CodeCellEditorView( CodeCellState codeCellState, CodeCell codeCell, HtmlElement element) { if (codeCellState == null) { throw new ArgumentNullException(nameof(codeCellState)); } if (codeCell == null) { throw new ArgumentNullException(nameof(codeCell)); } if (element == null) { throw new ArgumentNullException(nameof(element)); } this.state = codeCellState; this.jsContext = element.Context; Cell = codeCell; codeEditor = jsContext.GlobalObject.xiexports.monaco.WorkbookCodeEditor(jsContext.CreateObject(o => { o.placeElem = element; o.readOnly = false; o.fontSize = Prefs.UI.Font.GetSize(); o.showLineNumbers = Prefs.Editor.ShowLineNumbers.GetValue(); o.onFocus = (ScriptAction)HandleFocus; o.onChange = (ScriptAction)HandleChange; o.onCursorUpDown = (ScriptFunc)HandleCursorUpDown; o.onEnter = (ScriptFunc)HandleEnter; o.theme = GetThemeName(); o.wrapLongLines = Prefs.Submissions.WrapLongLinesInEditor.GetValue(); })); codeCell.CodeAnalysisBuffer.TextChanged += HandleBufferTextChanged; codeEditor.setText(codeCell.Buffer.Value); preferenceSubscription = PreferenceStore.Default.Subscribe(change => { if (change.Key == Prefs.UI.Font.Key) { // TODO: Figure out why this doesn't appear to update font size in completion window codeEditor.setFontSize(Prefs.UI.Font.GetSize()); } else if (change.Key == Prefs.Editor.ShowLineNumbers.Key) { codeEditor.setShowLineNumbers(Prefs.Editor.ShowLineNumbers.GetValue()); } else if (change.Key == Prefs.UI.Theme.UseHighContrast.Key || change.Key == Prefs.UI.Theme.ThemeName.Key) { codeEditor.setTheme(GetThemeName()); } else if (change.Key == Prefs.Submissions.WrapLongLinesInEditor.Key) { codeEditor.setWordWrap(Prefs.Submissions.WrapLongLinesInEditor.GetValue()); } }); }