Submit comment on blur or selection change

This commit is contained in:
James Allen 2017-02-14 13:41:04 +01:00
parent cc0986b4da
commit b48f57c2cb
4 changed files with 19 additions and 11 deletions

View file

@ -332,6 +332,7 @@ script(type='text/ng-template', id='addCommentEntryTemplate')
ng-keypress="handleCommentKeyPress($event);"
placeholder="Add your comment here"
focus-on="comment:new:open"
ng-blur="submitNewComment()"
)
.rp-entry-actions
button.rp-entry-button(

View file

@ -20,8 +20,8 @@ define [
@rangesTracker = doc.ranges
@connectToRangesTracker()
@$scope.$on "comment:add", (e, thread_id) =>
@addCommentToSelection(thread_id)
@$scope.$on "comment:add", (e, thread_id, offset, length) =>
@addCommentToSelection(thread_id, offset, length)
@$scope.$on "comment:select_line", (e) =>
@selectLineIfNoSelection()
@ -45,7 +45,7 @@ define [
@recalculateReviewEntriesScreenPositions()
changingSelection = false
onChangeSelection = (args...) =>
onChangeSelection = () =>
# Deletes can send about 5 changeSelection events, so
# just act on the last one.
if !changingSelection
@ -53,7 +53,6 @@ define [
@$scope.$evalAsync () =>
changingSelection = false
@updateFocus()
@recalculateReviewEntriesScreenPositions()
onResize = () =>
@recalculateReviewEntriesScreenPositions()
@ -64,11 +63,13 @@ define [
bindToAce = () =>
@editor.on "changeSelection", onChangeSelection
@editor.on "change", onChangeSelection # Selection also moves with updates elsewhere in the document
@editor.on "changeSession", onChangeSession
@editor.renderer.on "resize", onResize
unbindFromAce = () =>
@editor.off "changeSelection", onChangeSelection
@editor.off "change", onChangeSelection
@editor.off "changeSession", onChangeSession
@editor.renderer.off "resize", onResize
@ -174,10 +175,11 @@ define [
# @rangesTracker.applyOp op # Will apply via sharejs
@$scope.sharejsDoc.submitOp op
addCommentToSelection: (thread_id) ->
range = @editor.getSelectionRange()
content = @editor.getSelectedText()
offset = @_aceRangeToShareJs(range.start)
addCommentToSelection: (thread_id, offset, length) ->
start = @_shareJsOffsetToAcePosition(offset)
end = @_shareJsOffsetToAcePosition(offset + length)
range = new Range(start.row, start.column, end.row, end.column)
content = @editor.session.getTextRange(range)
@addComment(offset, content, thread_id)
selectLineIfNoSelection: () ->

View file

@ -280,6 +280,7 @@ define [
entries["add-comment"] = {
type: "add-comment"
offset: selection_offset_start
length: selection_offset_end - selection_offset_start
}
for id, entry of entries
@ -310,10 +311,15 @@ define [
$scope.$broadcast "review-panel:layout"
$scope.submitNewComment = (content) ->
return if !content? or content == ""
doc_id = $scope.editor.open_doc_id
entries = getDocEntries(doc_id)
return if !entries["add-comment"]?
{offset, length} = entries["add-comment"]
thread_id = RangesTracker.generateId()
thread = getThread(thread_id)
thread.submitting = true
$scope.$broadcast "comment:add", thread_id
$scope.$broadcast "comment:add", thread_id, offset, length
$http.post("/project/#{$scope.project_id}/thread/#{thread_id}/messages", {content, _csrf: window.csrfToken})
.error (error) ->
ide.showGenericMessageModal("Error submitting comment", "Sorry, there was a problem submitting your comment")

View file

@ -28,10 +28,9 @@ define [
if ev.keyCode == 13 and !ev.shiftKey and !ev.ctrlKey and !ev.metaKey
ev.preventDefault()
if scope.state.content.length > 0
ev.target.blur()
scope.submitNewComment()
scope.submitNewComment = () ->
scope.onSubmit { content: scope.state.content }
scope.state.isAdding = false
scope.state.content = ""
scope.state.content = ""