private void ExpressionTextBox_KeyPress(object s, KeyPressEventArgs e) { if (_sharedViewState.IsExponent) { if (SpecialSymbols.AsciiForSuperscripts.Contains(e.KeyChar)) { e.KeyChar = SpecialSymbols.AsciiToSuperscript(e.KeyChar); } } if (IsOperator(e.KeyChar)) { if (e.KeyChar == SpecialSymbols.ExponentModeSymbol) { _sharedViewState.IsExponent = !_sharedViewState.IsExponent; _showCaret(); // EventAggregator.Instance.Publish<ExponentModeChangedEvent>(new ExponentModeChangedEvent(_sharedViewState.IsExponent)); e.Handled = true; //return; } if (e.KeyChar == '*') { e.KeyChar = SpecialSymbols.DotSymbol; //for (int i = 0; i < this.AutoCompleteCustomSource.Count; i++) // this.AutoCompleteCustomSource[i] += Text + e.KeyChar; } } }
private void ApplyAutocomplete(AutocompleteItem item, Range fragment) { var newText = item.GetTextForReplace(); //replace text of fragment var index = fragment.Text.IndexOfAny(SpecialSymbols.SuperscriptsWithoutSpace.ToCharArray()); if (index == 0) { newText = SpecialSymbols.AsciiToSuperscript(newText); } else if (index > 0) { newText = fragment.Text.Substring(0, index) + SpecialSymbols.AsciiToSuperscript(newText); } else if (SharedViewState.Instance.IsExponent) { newText = fragment.Text + SpecialSymbols.AsciiToSuperscript(newText); } fragment.Text = newText; fragment.TargetWrapper.TargetControl.Focus(); }
protected override void OnKeyDown(KeyEventArgs e) { if (e.Key == Key.D6 && (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) { _sharedViewState.IsExponent = !_sharedViewState.IsExponent; e.Handled = true; return; } if (_sharedViewState.IsExponent) { var ch = GetCharFromKey(e.Key); if (SpecialSymbols.IsAscii(ch)) { var str = SpecialSymbols.AsciiToSuperscript(ch.ToString()); if (string.IsNullOrWhiteSpace(str)) { } else { TextArea.PerformTextInput(str); } } e.Handled = true; } else { if (e.Key == Key.Multiply) // e = new KeyEventArgs(e.KeyboardDevice, e.InputSource, e.Timestamp, GlobalConfig.dotSymbol); { TextArea.PerformTextInput(SpecialSymbols.DotSymbol + ""); e.Handled = true; } else { base.OnKeyDown(e); } } }
public ModeDeterminer(ITslCompiler tslCompiler) { _tslCompiler = tslCompiler; // FindX = new Regex(pre + "x" + post, RegexOptions.Compiled); FindY = new Regex( mergePatterns(pre + "y" + post, preExponent + SpecialSymbols.AsciiToSuperscript("y") + postExponent), RegexOptions.Compiled); FindZ = new Regex( mergePatterns(pre + "z" + post, preExponent + SpecialSymbols.AsciiToSuperscript("z") + postExponent), RegexOptions.Compiled); FindI = new Regex( mergePatterns(pre + "i" + post, preExponent + SpecialSymbols.AsciiToSuperscript("i") + postExponent), RegexOptions.Compiled); }
private void ApplyAutocomplete(AutocompleteItem item, Range fragment) { var newText = item.GetTextForReplace(); //replace text of fragment var expressionTextBox = (TargetControlWrapper.TargetControl as ExpressionTextBox); var scintillaEditor = (TargetControlWrapper.TargetControl as ScintillaCodeEditorControl); var isExponent = false; if (expressionTextBox != null) { isExponent = expressionTextBox.ExponentMode; } else if (scintillaEditor != null) { isExponent = scintillaEditor.ExponentMode; } fragment.Text = isExponent ? SpecialSymbols.AsciiToSuperscript(newText) : newText; fragment.TargetWrapper.TargetControl.Focus(); }
private void NumericTextBox_TextChanged(object sender, EventArgs e) { if (!Text.Contains('E') && !Text.Contains('e')) { return; } var chunks = Text.Split('E', 'e', 'i'); if (!Text.Contains('i')) { Text = chunks[0] + SpecialSymbols.DotSymbol + "10" + SpecialSymbols.AsciiToSuperscript(chunks[1]); } else { //1. -1E-11 + 5E-11i if (Text.Count(c => c == 'E') >= 2) { var midChunk = chunks[1].Insert(chunks[1].LastIndexOfAny(new[] { '+', '-' }) + 1, "("); var midChunks = midChunk.Split(new[] { "+(", "-(", "+ (", "- (" }, StringSplitOptions.RemoveEmptyEntries); Text = chunks[0] + SpecialSymbols.DotSymbol + "10" + SpecialSymbols.AsciiToSuperscript(midChunks[0]) + midChunk.Substring(midChunk.LastIndexOfAny(new[] { '+', '-' })) + SpecialSymbols.DotSymbol + "10" + SpecialSymbols.AsciiToSuperscript(chunks[2]) + ")" + SpecialSymbols.DotSymbol + "i"; } else { if (chunks[0].Count(c => c == '+') == 0 && Regex.IsMatch(chunks[1], @"^[+\-]?(\d+)$") && Regex.IsMatch(chunks[0], @"^-?(\d+\.?\d*)$")) { //2. 5E-11i//-5·16²²·i Text = "(" + chunks[0] + SpecialSymbols.DotSymbol + "10" + SpecialSymbols.AsciiToSuperscript(chunks[1]) + ")" + SpecialSymbols.DotSymbol + "i"; } //3. -1 + 5E-11i//-5·16²²·i+22 else if (Regex.IsMatch(chunks[0], @"^-?(\d+\.?\d*)[\+\-](\d+\.?\d*)$")) { Text = chunks[0].Insert(chunks[0].LastIndexOfAny(new[] { '+', '-' }) + 1, "(") + SpecialSymbols.DotSymbol + "10" + SpecialSymbols.AsciiToSuperscript(chunks[1]) + ")" + SpecialSymbols.DotSymbol + "i"; } //4. -1E-11 + 5i else if (Regex.IsMatch(chunks[1], @"^[+\-]?(\d+)[\+\-](\d+\.?\d*)$")) { var chunk11 = chunks[1].Substring(0, chunks[1].LastIndexOfAny(new[] { '+', '-' })); var chunk12 = chunks[1].Substring(chunks[1].LastIndexOfAny(new[] { '+', '-' })); Text = chunks[0] + SpecialSymbols.DotSymbol + "10" + SpecialSymbols.AsciiToSuperscript(chunk11) + chunk12 + SpecialSymbols.DotSymbol + "i"; } } } }
private void SciriptingRichTextBox_KeyPress(object s, KeyPressEventArgs e) { if (e.KeyChar < 32) { // Prevent control characters from getting inserted into the text buffer e.Handled = true; return; } if (_sharedViewState.IsExponent) { if (SpecialSymbols.AsciiForSuperscripts.Contains(e.KeyChar)) { e.KeyChar = SpecialSymbols.AsciiToSuperscript(e.KeyChar); } } if (IsOperator(e.KeyChar)) { if (e.KeyChar == SpecialSymbols.ExponentModeSymbol) { _sharedViewState.IsExponent = !_sharedViewState.IsExponent; //_showCaret(); e.Handled = true; //return; //this.Refresh(); } if (e.KeyChar == '*') { e.KeyChar = SpecialSymbols.DotSymbol; //for (int i = 0; i < this.AutoCompleteCustomSource.Count; i++) // this.AutoCompleteCustomSource[i] += Text + e.KeyChar; } } /* * if (e.KeyChar == '^') * { * ExponentMode = !ExponentMode; * e.Handled = true; * return; * } * * if (ExponentMode) * { * e.Handled = true; * * if (SpecialSymbols.AsciiForSuperscripts.Contains(e.KeyChar)) * { * var str = SpecialSymbols.AsciiToSuperscript(e.KeyChar + ""); * * var byteOffset = CurrentPosition; * * var range = GetTextRange(0, byteOffset); * var charOffset = range.Length; * * var positionInDocument = charOffset; * * var caretPos = AnchorPosition; //Caret.Position; * if (!string.IsNullOrEmpty(str) && !string.IsNullOrWhiteSpace(str)) * { * Text = Text.Insert(positionInDocument, str); * GotoPosition(caretPos + 1); * Focus(); * } * } * } * else if (e.KeyChar == '*') * { * e.KeyChar = SpecialSymbols.DotSymbol; * }*/ }