Esempio n. 1
0
        public void Apply(string text, WordHighlight wordHighlight)
        {
            if (string.IsNullOrEmpty(text))
            {
                TextBefore = TextHighlight = TextAfter = "";
                return;
            }
            if (wordHighlight == null)
            {
                TextBefore    = text;
                TextHighlight = TextAfter = "";
                return;
            }
            var startIndex = wordHighlight.StartIndex;

            if (startIndex < 0)
            {
                startIndex = 0;
            }
            var endIndex = wordHighlight.StartIndex + wordHighlight.Length;

            if (endIndex > text.Length)
            {
                endIndex = text.Length;
            }
            TextBefore    = text.Substring(0, startIndex);
            TextHighlight = text.Substring(startIndex, endIndex - startIndex);
            TextAfter     = text.Substring(endIndex, text.Length - endIndex);
        }
Esempio n. 2
0
        public void Test_SplitSection()
        {
            // .... "the box" play with it to test it out
            const int OFFSET     = 200;
            const int LENGTH     = 100;
            var       sectionAll = new DocSection(OFFSET, LENGTH);
            var       highlights = new WordHighlight[] {
                new WordHighlight(OFFSET + 10, 1),
                new WordHighlight(OFFSET + 20, 1),
                new WordHighlight(OFFSET + 30, 1),
                new WordHighlight(OFFSET + 40, 1),
                new WordHighlight(OFFSET + 50, 1),
                new WordHighlight(OFFSET + 50, 1),
                new WordHighlight(OFFSET + 60, 1),
                new WordHighlight(OFFSET + 70, 1),
                new WordHighlight(OFFSET + 80, 1),
                new WordHighlight(OFFSET + 90, 1),
            };
            var splits = Utils.SplitSection(sectionAll, highlights);

            // .... length as expected?
            Assert.AreEqual(highlights.Length, splits.Count());
            // .... every char accounted for?
            Assert.AreEqual(LENGTH, splits.Select(x => x.Length).Sum());
            // .... all splits inside the "box"?
            foreach (var split in splits)
            {
                Assert.IsTrue(split.StartIndex >= OFFSET);
                Assert.IsTrue(split.StartIndex + split.Length <= OFFSET + LENGTH);
            }
        }
 private void _CmdUser_TriggerBuild()
 {
     try
     {
         var prolog = new PrologEngine(persistentCommandHistory: false);
         prolog.ConsultFromString(CodeDocument.Text);
         prolog.GetFirstSolution(CodeDocumentQuery.Text);
         MyConsole.WriteLine("----------------------");
         foreach (var sol in prolog.GetEnumerator())
         {
             var errorInfo = MyPrologUtils.TryToGetErrorFromPrologSolution(sol);
             if (errorInfo != null)
             {
                 CurErrorMessage = errorInfo.Message;
                 var errorLine = CodeDocumentQuery.GetLineByNumber(1);
                 CurErrorWordHighlightQuery = new WordHighlight(errorLine.Offset, errorLine.Length);
                 break;
             }
             var stringified = sol.VarValuesIterator.Select(val => $"{val.Name}:{val.Value}").StringJoin(", ");
             MyConsole.WriteLine(stringified);
         }
     }
     catch (Exception ex)
     {
         var errorInfo = MyPrologUtils.TryToGetErrorFromException(ex);
         if (errorInfo.Line != null)
         {
             var errorLine = CodeDocument.GetLineByNumber(errorInfo.Line.Value);
             CurErrorWordHighlight = new WordHighlight(errorLine.Offset, errorLine.Length);
         }
         CurErrorMessage = errorInfo.Message;
     }
 }
Esempio n. 4
0
 private void DocReader_WordRead(WordHighlight word)
 {
     Highlight = word?.MakeCopy();
     if (word != null)
     {
         Progress = GetProgressValue(word.StartIndex);
     }
 }
Esempio n. 5
0
 private void OnWordHighlightChanged(WordHighlight oldValue, WordHighlight newValue)
 {
     Scope.Apply(Text, WordHighlight);
 }
 public DocumentState(int start)
 {
     Word = new WordHighlight(start, 0);
 }
 private void ttsService_wordCallback(string text, int offset, int start, int length)
 {
     CurHighlightRegion = new WordHighlight(start, length);
 }
Esempio n. 8
0
 public static void SetHighlightWord(DependencyObject obj, WordHighlight value)
 {
     obj.SetValue(HighlightWordProperty, value);
 }