// ReSharper disable once SuggestBaseTypeForParameter /// <summary> /// Is the selected offset at the end of the last block /// </summary> /// <param name="subOffset">The index that the user selected</param> /// <param name="blockIndex">The index of the block containing the selected segment</param> /// <param name="selectedDivElement">The selected segment</param> /// <returns></returns> private bool SplitIsAtEndOfLastBlock(int subOffset, int blockIndex, GeckoDivElement selectedDivElement) { // not if this is not the last block if (blockIndex < m_originalBlocks.Count - 1) { return(false); } // not if offset is not at end of segment var segmentText = m_verseNumberRegex.Replace(selectedDivElement.InnerHtml, ""); if (segmentText.Length > subOffset) { return(false); } // this is the last block, and offset is at the end of a segment var nextElement = selectedDivElement.NextSibling as GeckoHtmlElement; while (nextElement != null) { // if the next element is a splittext div, the current offset is not at the end of the last block if (nextElement.ClassName == "splittext") { return(false); } nextElement = nextElement.NextSibling as GeckoHtmlElement; } return(true); }
private bool DetermineSplitLocationAtStartOfVerse(GeckoDivElement blockElement, string verseElementInnerHtml) { BlockToSplit = m_originalBlocks[int.Parse(blockElement.Id)]; var ichThisVerse = blockElement.InnerHtml.IndexOf(verseElementInnerHtml, StringComparison.Ordinal); var ichPrecedingVerse = blockElement.InnerHtml.LastIndexOf("<sup>", ichThisVerse, StringComparison.Ordinal); ichPrecedingVerse = blockElement.InnerHtml.LastIndexOf("<sup>", ichPrecedingVerse, StringComparison.Ordinal); if (ichPrecedingVerse < 0) { VerseToSplit = BlockToSplit.InitialVerseNumberOrBridge; } else { var regexVerse = new Regex(@"\<sup\>(‏)?(?<verse>[0-9-]+)*(( )|( ))"); var match = regexVerse.Match(blockElement.InnerHtml, ichPrecedingVerse); if (!match.Success) { Debug.Fail("HTML data for verse number not formed as expected"); // ReSharper disable once HeuristicUnreachableCode return(false); } VerseToSplit = match.Result("${verse}"); } CharacterOffsetToSplit = BookScript.kSplitAtEndOfVerse; return(true); }
public void ScrollElementIntoView(string elementId, int adjustment = 0) { var element = m_geckoBrowser.Document.GetElementById(elementId); if (element == null) { return; } var div = new GeckoDivElement(element.DomObject); div.ScrollIntoView(true); div.Parent.ScrollTop += adjustment; }
// ReSharper disable once SuggestBaseTypeForParameter /// <summary> /// Given the split location in the selected segment, calculate the split location in the original block /// </summary> /// <param name="subOffset">The index that the user selected</param> /// <param name="blockIndex">The index of the block containing the selected segment</param> /// <param name="verseToSplit">The verse number to look for, if null, search the whole block</param> /// <param name="selectedDivElement">The selected segment</param> /// <param name="selectLastIndex">If true, ignore the subOffset and return the last position in the block</param> /// <returns></returns> private int GetSplitIndexInVerse(int subOffset, int blockIndex, string verseToSplit, GeckoDivElement selectedDivElement, bool selectLastIndex = false) { // get the text from the previous splittext elements in this block var sb = new StringBuilder(); var previousElement = selectedDivElement.PreviousSibling as GeckoHtmlElement; while (previousElement != null) { if (previousElement.ClassName == "splittext") { // stop looking if we've moved to a different block if (int.Parse(previousElement.GetAttribute("data-blockid")) != blockIndex) { break; } // stop looking if we've moved to a different verse if (previousElement.GetAttribute("data-verse") != verseToSplit) { break; } var textWithoutVerseNumbers = m_verseNumberRegex.Replace(previousElement.InnerHtml, ""); var unencodedText = System.Web.HttpUtility.HtmlDecode(textWithoutVerseNumbers); sb.Append(unencodedText); } previousElement = previousElement.PreviousSibling as GeckoHtmlElement; } // get the part of the current element text that is included var lastSegement = m_verseNumberRegex.Replace(selectedDivElement.InnerHtml, ""); // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression if (selectLastIndex) { sb.Append(lastSegement); } else { sb.Append(lastSegement.Substring(0, subOffset)); } return(sb.Length); }