Skip to content

Commit 735fcea

Browse files
committed
Merge branch 'develop' into art/user-profile
2 parents 33f04c1 + affda6f commit 735fcea

6 files changed

Lines changed: 40 additions & 30 deletions

File tree

app/assets/javascripts/comments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ $(() => {
387387

388388
const $tgt = $(ev.target);
389389
const content = $tgt.val();
390-
const splat = content.split(' ');
390+
const splat = content.split(/\s+/);
391391
const caretPos = $tgt[0].selectionStart;
392392
const [currentWord, posInWord] = QPixel.currentCaretSequence(splat, caretPos);
393393

app/assets/javascripts/markdown.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ $(() => {
2929
}
3030
});
3131

32-
$('#markdown-link-name, #markdown-link-url').on('keydown', (ev) => {
33-
if (ev.keyCode === 13) {
34-
// don't submit post form on enter in link modal
35-
ev.stopPropagation();
32+
QPixel.DOM?.addSelectorListener('keypress', '#markdown-link-name, #markdown-link-url', (ev) => {
33+
if (ev instanceof KeyboardEvent && ev.key === 'Enter') {
34+
ev.preventDefault();
3635
}
3736
});
3837

app/controllers/tags_controller.rb

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -225,30 +225,34 @@ def merge
225225
end
226226

227227
def nuke
228-
Post.transaction do
229-
AuditLog.admin_audit event_type: 'tag_nuke', related: @tag, user: current_user,
230-
comment: "#{@tag.name} (#{@tag.id})"
231-
232-
tables = ['posts_tags', 'categories_moderator_tags', 'categories_required_tags', 'categories_topic_tags',
233-
'post_history_tags', 'suggested_edits_tags', 'suggested_edits_before_tags']
234-
235-
# Remove tag from caches
236-
caches_sql = 'UPDATE posts INNER JOIN posts_tags ON posts.id = posts_tags.post_id ' \
237-
'SET posts.tags_cache = REPLACE(posts.tags_cache, ?, ?) ' \
238-
'WHERE posts_tags.tag_id = ?'
239-
exec_sql([caches_sql, "\n- #{@tag.name}\n", "\n", @tag.id])
228+
if @tag.children.any?
229+
flash[:error] = 'Cannot delete a tag that has children.'
230+
else
231+
Post.transaction do
232+
AuditLog.admin_audit event_type: 'tag_nuke', related: @tag, user: current_user,
233+
comment: "#{@tag.name} (#{@tag.id})"
234+
235+
tables = ['posts_tags', 'categories_moderator_tags', 'categories_required_tags', 'categories_topic_tags',
236+
'post_history_tags', 'suggested_edits_tags', 'suggested_edits_before_tags']
237+
238+
# Remove tag from caches
239+
caches_sql = 'UPDATE posts INNER JOIN posts_tags ON posts.id = posts_tags.post_id ' \
240+
'SET posts.tags_cache = REPLACE(posts.tags_cache, ?, ?) ' \
241+
'WHERE posts_tags.tag_id = ?'
242+
exec_sql([caches_sql, "\n- #{@tag.name}\n", "\n", @tag.id])
243+
244+
# Delete all references to the tag
245+
tables.each do |tbl|
246+
sql = "DELETE FROM #{tbl} WHERE tag_id = ?"
247+
exec_sql([sql, @tag.id])
248+
end
240249

241-
# Delete all references to the tag
242-
tables.each do |tbl|
243-
sql = "DELETE FROM #{tbl} WHERE tag_id = ?"
244-
exec_sql([sql, @tag.id])
250+
# Nuke it
251+
@tag.destroy
245252
end
246253

247-
# Nuke it
248-
@tag.destroy
254+
flash[:success] = "Deleted #{@tag.name}"
249255
end
250-
251-
flash[:success] = "Deleted #{@tag.name}"
252256
redirect_to category_tags_path(@category)
253257
end
254258

app/views/comment_threads/_expanded.html.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@
5959
<%= render 'comments/skip_deleted', inline: inline, num_skipped: skipped_deleted, thread: thread %>
6060
<% skipped_deleted = 0 %>
6161
<% end %>
62-
<% if shown_comments_count > max_shown_comments && comment.id.to_i == comment_id.to_i %>
63-
<%= render 'comments/skip_more', shown_count: shown_comments_count, thread: thread %>
62+
<% skipped_more = thread.reply_count - shown_comments_count %>
63+
<% if shown_comments_count > max_shown_comments && skipped_more.positive? && comment.id.to_i == comment_id.to_i %>
64+
<%= render 'comments/skip_more', num_skipped: skipped_more, thread: thread %>
6465
<% end %>
6566
<div class="widget--body" role="listitem">
6667
<%= render 'comments/comment', comment: comment, pingable: pingable %>

app/views/comments/_skip_more.html.erb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
Renders widgets indicating that there more comments are not shown
33
44
Variables:
5-
shown_count : number of comments shown on the thread
5+
num_skipped : number of comments skipped on the thread
66
thread : CommentThread to display the widget for
77
%>
88

99
<div class="widget--body widget--more-comments" role="listitem">
10-
<% skipped_count = thread.reply_count - shown_count %>
11-
<p>Skipping <%= pluralize(skipped_count, 'more comment') %></p>
10+
<p>Skipping <%= pluralize(num_skipped, 'more comment') %></p>
1211
</div>

app/views/tags/nuke_warning.html.erb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
<h1>Delete tag <%= @tag.name %></h1>
88

9+
<% if @tag.children.any? %>
10+
<div class="notice is-warning has-color-yellow-900">
11+
<p>Tags with children cannot be deleted. Please reparent the children first.</p>
12+
</div>
13+
<% else %>
14+
915
<div class="notice is-danger has-color-red-900">
1016
<p>
1117
Deleting a tag results in making it seem to have never existed in the first place. No record will be kept of the tag.
@@ -27,3 +33,4 @@
2733
role: 'button' do %>
2834
I understand, delete <%= @tag.name %>
2935
<% end %>
36+
<% end %>

0 commit comments

Comments
 (0)