Exemple #1
0
 /// <summary>
 /// called when the client changes our Control.Text... we need to them move that into the html
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected virtual void OnTextChanged(object sender, EventArgs e)
 {
     SetText(Text);
     AdjustHeight();
     LanguageForm.AdjustSpansForTextChange(_previousText, Text, Spans);
     _previousText = Text;
 }
        public void AdjustSpans_Delete()
        {
            // In these tests, we're testing (deleting) edits to the formatted string
            // "This is a <span class='Strong'>test</span> of <span class='Weak'>something</span> or other."
            // See http://jira.palaso.org/issues/browse/WS-34799 for a discussion of what we want to achieve.
            List <LanguageForm.FormatSpan> spans = new List <LanguageForm.FormatSpan>();
            string oldString = "This is a test of something or other.";

            // before any spans (remove 3 characters)
            var expected = CreateSpans(spans, -3, 0, -3, 0);

            LanguageForm.AdjustSpansForTextChange(oldString, "This a test of something or other.", spans);
            VerifySpans(expected, spans);

            // before any spans, but next to first span (remove 2 characters)
            expected = CreateSpans(spans, -2, 0, -2, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is test of something or other.", spans);
            VerifySpans(expected, spans);

            // start before any spans, but including part of first span (remove 2 before and 2 inside span)
            expected = CreateSpans(spans, -2, -2, -4, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is st of something or other.", spans);
            VerifySpans(expected, spans);

            // start before any spans, but extending past first span (remove 2 before, 4 inside, and 4 after/between)
            // The span length going negative is okay, and the same as going to zero: the span is ignored thereafter.
            expected = CreateSpans(spans, -2, -8, -10, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is something or other.", spans);
            VerifySpans(expected, spans);

            // delete exactly the first span (remove 4 inside)
            expected = CreateSpans(spans, 0, -4, -4, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a  of something or other.", spans);
            VerifySpans(expected, spans);

            // after any spans (effectively no change)
            expected = CreateSpans(spans, 0, 0, 0, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a test of something or other", spans);
            VerifySpans(expected, spans);

            // after any spans, but adjacent to last span (effectively no change)
            expected = CreateSpans(spans, 0, 0, 0, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a test of somethingther.", spans);
            VerifySpans(expected, spans);

            // delete from middle of first span to middle of second span
            expected = CreateSpans(spans, 0, -2, -6, -7);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a teng or other.", spans);
            VerifySpans(expected, spans);

            // change text without changing length of string
            // (alas, we can't handle this kind of wholesale change, so effectively no change to the spans)
            expected = CreateSpans(spans, 0, 0, 0, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "That is a joke of some other topic!!!", spans);
            VerifySpans(expected, spans);
        }
Exemple #3
0
 private void OnTextChanged(object sender, EventArgs e)
 {
     //only first change per focus session will be logged
     if (!_haveAlreadyLoggedTextChanged && Focused
         /*try not to report when code is changing us*/)
     {
         _haveAlreadyLoggedTextChanged = true;
         Logger.WriteMinorEvent("First_TextChange (could be paste via mouse) {0}:{1}",
                                _nameForLogging,
                                _writingSystem.Id);
     }
     LanguageForm.AdjustSpansForTextChange(_previousText, Text, Spans);
     _previousText = Text;
 }
        public void UpdateSpans_Insert()
        {
            // In these tests, we're testing (inserting) edits to the formatted string
            // "This is a <span class='Strong'>test</span> of <span class='Weak'>something</span> or other."
            // See http://jira.palaso.org/issues/browse/WS-34799 for a discussion of what we want to achieve.
            List <LanguageForm.FormatSpan> spans = new List <LanguageForm.FormatSpan>();
            string oldString = "This is a test of something or other.";

            // before any spans (add 3 characters)
            var expected = CreateSpans(spans, 3, 0, 3, 0);

            LanguageForm.AdjustSpansForTextChange(oldString, "This isn't a test of something or other.", spans);
            VerifySpans(expected, spans);

            // before any spans, but right next to the first span (add 5 characters)
            expected = CreateSpans(spans, 5, 0, 5, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a good test of something or other.", spans);
            VerifySpans(expected, spans);

            // after any spans (add 5 characters, but spans don't change)
            expected = CreateSpans(spans, 0, 0, 0, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a test of something else or other.", spans);
            VerifySpans(expected, spans);

            // inside the first span (increase its length by 2)
            expected = CreateSpans(spans, 0, 2, 2, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a tessst of something or other.", spans);
            VerifySpans(expected, spans);

            // after the first span, but right next to it (increase its length by 3)
            expected = CreateSpans(spans, 0, 3, 3, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a testing of something or other.", spans);
            VerifySpans(expected, spans);

            // inside the second span (increase its length by 9)
            expected = CreateSpans(spans, 0, 0, 0, 9);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a test of some kind of thing or other.", spans);
            VerifySpans(expected, spans);

            // between the two spans (effectively add 1 character)
            expected = CreateSpans(spans, 0, 0, 1, 0);
            LanguageForm.AdjustSpansForTextChange(oldString, "This is a test for something or other.", spans);
            VerifySpans(expected, spans);
        }
Exemple #5
0
 private void OnTextChanged(object sender, EventArgs e)
 {
     LanguageForm.AdjustSpansForTextChange(_previousText, Text, Spans);
     _previousText = Text;
 }