From 941e16bb11ced02e0481badc53924f0ccaf6c270 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Tue, 18 Aug 2015 10:31:18 -0700 Subject: [PATCH] fix(*): A few patches for minor sentry errors Summary: Fix edge cases where _getRangeInScope is null, fix logic errors fix(1932) Edge case where we can't find a container for the message Id we're asked to scroll to Check view exists before trying to perform actions. Will be fixed once keybindings are a React container Test Plan: Run specs Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1906 --- .../lib/contenteditable-component.cjsx | 42 +++++++++---------- .../message-list/lib/message-list.cjsx | 4 +- .../thread-list/lib/thread-list.cjsx | 4 ++ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/internal_packages/composer/lib/contenteditable-component.cjsx b/internal_packages/composer/lib/contenteditable-component.cjsx index b4bc9068f..60cfb7f07 100644 --- a/internal_packages/composer/lib/contenteditable-component.cjsx +++ b/internal_packages/composer/lib/contenteditable-component.cjsx @@ -481,7 +481,10 @@ class ContenteditableComponent extends React.Component # Don't bother computing client rects if no scroll method has been provided else if @props.onScrollTo - rect = @_getRangeInScope().getBoundingClientRect() + rangeInScope = @_getRangeInScope() + return unless rangeInScope + + rect = rangeInScope.getBoundingClientRect() if @_isEmptyBoudingRect(rect) rect = @_getSelectionRectFromDOM(selection) @@ -763,31 +766,24 @@ class ContenteditableComponent extends React.Component toolbarPos: toolbarPos linkToModify: @_linkHoveringOver editAreaWidth: editAreaWidth + + else if not @_selection? or @_selection.isCollapsed + @_hideToolbar() + else - if not @_selection? or @_selection.isCollapsed + rect = @_getRangeInScope()?.getBoundingClientRect() + if not rect or @_isEmptyBoudingRect(rect) @_hideToolbar() else - if @_selection.isCollapsed - linkRect = linksInside[0].getBoundingClientRect() - isEmptyRect = @_isEmptyBoudingRect(linkRect) - [left, top, editAreaWidth, toolbarPos] = @_getToolbarPos(linkRect) - else - selectionRect = @_getRangeInScope().getBoundingClientRect() - isEmptyRect = @_isEmptyBoudingRect(selectionRect) - [left, top, editAreaWidth, toolbarPos] = @_getToolbarPos(selectionRect) - - if isEmptyRect - @setState - toolbarVisible: false - else - @setState - toolbarVisible: true - toolbarMode: "buttons" - toolbarTop: top - toolbarLeft: left - toolbarPos: toolbarPos - linkToModify: null - editAreaWidth: editAreaWidth + [left, top, editAreaWidth, toolbarPos] = @_getToolbarPos(rect) + @setState + toolbarVisible: true + toolbarMode: "buttons" + toolbarTop: top + toolbarLeft: left + toolbarPos: toolbarPos + linkToModify: null + editAreaWidth: editAreaWidth _selectionInScope: (selection) => return false if not selection? diff --git a/internal_packages/message-list/lib/message-list.cjsx b/internal_packages/message-list/lib/message-list.cjsx index fe87651e0..f34e78ae9 100755 --- a/internal_packages/message-list/lib/message-list.cjsx +++ b/internal_packages/message-list/lib/message-list.cjsx @@ -383,7 +383,9 @@ class MessageList extends React.Component _onChildScrollRequest: ({messageId, rect}={}) => return if @_draftScrollInProgress if messageId - @refs.messageWrap.scrollTo(@_getMessageContainer(messageId), { + messageElement = @_getMessageContainer(messageId) + return unless messageElement + @refs.messageWrap.scrollTo(messageElement, { position: ScrollRegion.ScrollPosition.Visible }) else if rect diff --git a/internal_packages/thread-list/lib/thread-list.cjsx b/internal_packages/thread-list/lib/thread-list.cjsx index bb155fcd6..5ac362cff 100644 --- a/internal_packages/thread-list/lib/thread-list.cjsx +++ b/internal_packages/thread-list/lib/thread-list.cjsx @@ -232,6 +232,8 @@ class ThreadList extends React.Component # Additional Commands _onStarItem: => + return unless ThreadListStore.view() + if WorkspaceStore.layoutMode() is "list" and WorkspaceStore.topSheet() is WorkspaceStore.Sheet.Thread Actions.toggleStarFocused() else if ThreadListStore.view().selection.count() > 0 @@ -240,6 +242,8 @@ class ThreadList extends React.Component Actions.toggleStarFocused() _onArchive: => + return unless ThreadListStore.view() + if WorkspaceStore.layoutMode() is "list" and WorkspaceStore.topSheet() is WorkspaceStore.Sheet.Thread Actions.archive() else if ThreadListStore.view().selection.count() > 0