private async void Editor_Loading(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(CodeContent)) { CodeContent = await FileIO.ReadTextAsync(await StorageFile.GetFileFromApplicationUriAsync(new System.Uri("ms-appx:///Content.txt"))); ButtonHighlightRange_Click(null, null); } // Ready for Code var languages = new Monaco.LanguagesHelper(Editor); var available_languages = await languages.GetLanguagesAsync(); //Debugger.Break(); await languages.RegisterHoverProviderAsync("csharp", new EditorHoverProvider()); await languages.RegisterCompletionItemProviderAsync("csharp", new LanguageProvider()); _myCondition = await Editor.CreateContextKeyAsync("MyCondition", false); await Editor.AddCommandAsync(KeyCode.F5, async() => { var md = new MessageDialog("You Hit F5!"); await md.ShowAsync(); // Turn off Command again. _myCondition?.Reset(); // Refocus on CodeEditor Editor.Focus(FocusState.Programmatic); }, _myCondition.Key); await Editor.AddCommandAsync(KeyMod.CtrlCmd | KeyCode.KEY_R, async() => { var range = await Editor.GetModel().GetFullModelRangeAsync(); var md = new MessageDialog("Document Range: " + range.ToString()); await md.ShowAsync(); Editor.Focus(FocusState.Programmatic); }); await Editor.AddCommandAsync(KeyMod.CtrlCmd | KeyCode.KEY_W, async() => { var word = await Editor.GetModel().GetWordAtPositionAsync(await Editor.GetPositionAsync()); if (word == null) { var md = new MessageDialog("No Word Found."); await md.ShowAsync(); } else { var md = new MessageDialog("Word: " + word.Word + "[" + word.StartColumn + ", " + word.EndColumn + "]"); await md.ShowAsync(); } Editor.Focus(FocusState.Programmatic); }); await Editor.AddCommandAsync(KeyMod.CtrlCmd | KeyCode.KEY_L, async() => { var model = Editor.GetModel(); var line = await model.GetLineContentAsync((await Editor.GetPositionAsync()).LineNumber); var lines = await model.GetLinesContentAsync(); var count = await model.GetLineCountAsync(); var md = new MessageDialog("Current Line: " + line + "\nAll Lines [" + count + "]:\n" + string.Join("\n", lines)); await md.ShowAsync(); Editor.Focus(FocusState.Programmatic); }); await Editor.AddCommandAsync(KeyMod.CtrlCmd | KeyCode.KEY_U, async() => { var range = new Range(2, 10, 3, 8); var seg = await Editor.GetModel().GetValueInRangeAsync(range); var md = new MessageDialog("Segment " + range.ToString() + ": " + seg); await md.ShowAsync(); Editor.Focus(FocusState.Programmatic); }); await Editor.AddActionAsync(new TestAction()); }
private async void Editor_Loading(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(CodeContent)) { CodeContent = await FileIO.ReadTextAsync(await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Content.txt"))); ButtonHighlightRange_Click(null, null); } // Ready for Code var languages = new Monaco.LanguagesHelper(Editor); var available_languages = await languages.GetLanguagesAsync(); //Debugger.Break(); await languages.RegisterHoverProviderAsync("csharp", (model, position) => { // TODO: See if this can be internalized? Need to figure out the best pattern here to expose async method through WinRT, as can't use Task for 'async' language compatibility in WinRT Component... return(AsyncInfo.Run(async delegate(CancellationToken cancelationToken) { var word = await model.GetWordAtPositionAsync(position); if (word != null && word.Word != null && word.Word.IndexOf("Hit", 0, StringComparison.CurrentCultureIgnoreCase) != -1) { return new Hover(new string[] { "*Hit* - press the keys following together.", "Some **more** text is here.", "And a [link](https://www.github.com/)." }, new Range(position.LineNumber, position.Column, position.LineNumber, position.Column + 5)); } return default(Hover); })); }); await languages.RegisterCompletionItemProviderAsync("csharp", new LanguageProvider()); _myCondition = await Editor.CreateContextKeyAsync("MyCondition", false); await Editor.AddCommandAsync(Monaco.KeyCode.F5, async() => { var md = new MessageDialog("You Hit F5!"); await md.ShowAsync(); // Turn off Command again. _myCondition?.Reset(); // Refocus on CodeEditor Editor.Focus(FocusState.Programmatic); }, _myCondition.Key); await Editor.AddCommandAsync(Monaco.KeyMod.CtrlCmd | Monaco.KeyCode.KEY_R, async() => { var range = await Editor.GetModel().GetFullModelRangeAsync(); var md = new MessageDialog("Document Range: " + range.ToString()); await md.ShowAsync(); Editor.Focus(FocusState.Programmatic); }); await Editor.AddCommandAsync(Monaco.KeyMod.CtrlCmd | Monaco.KeyCode.KEY_W, async() => { var word = await Editor.GetModel().GetWordAtPositionAsync(await Editor.GetPositionAsync()); if (word == null) { var md = new MessageDialog("No Word Found."); await md.ShowAsync(); } else { var md = new MessageDialog("Word: " + word.Word + "[" + word.StartColumn + ", " + word.EndColumn + "]"); await md.ShowAsync(); } Editor.Focus(FocusState.Programmatic); }); await Editor.AddCommandAsync(Monaco.KeyMod.CtrlCmd | Monaco.KeyCode.KEY_L, async() => { var model = Editor.GetModel(); var line = await model.GetLineContentAsync((await Editor.GetPositionAsync()).LineNumber); var lines = await model.GetLinesContentAsync(); var count = await model.GetLineCountAsync(); var md = new MessageDialog("Current Line: " + line + "\nAll Lines [" + count + "]:\n" + string.Join("\n", lines)); await md.ShowAsync(); Editor.Focus(FocusState.Programmatic); }); await Editor.AddCommandAsync(Monaco.KeyMod.CtrlCmd | Monaco.KeyCode.KEY_U, async() => { var range = new Range(2, 10, 3, 8); var seg = await Editor.GetModel().GetValueInRangeAsync(range); var md = new MessageDialog("Segment " + range.ToString() + ": " + seg); await md.ShowAsync(); Editor.Focus(FocusState.Programmatic); }); await Editor.AddActionAsync(new TestAction()); }