Skip to content

Commit

Permalink
Merge pull request matrix-org#1725 from matrix-org/luke/fix-room-list…
Browse files Browse the repository at this point in the history
…-reordering

Fix order calculation logic when reordering a room
  • Loading branch information
dbkr authored Jan 30, 2018
2 parents ebfdd7c + c5a3a02 commit c7afaed
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/components/views/rooms/RoomList.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,18 +314,21 @@ module.exports = React.createClass({

// Is the tag ordered manually?
if (newTag && !newTag.match(/^(m\.lowpriority|im\.vector\.fake\.(invite|recent|direct|archived))$/)) {
const newList = Object.assign({}, this.state.lists[newTag]);
const newList = this.state.lists[newTag];

// If the room was moved "down" (increasing index) in the same list we
// need to use the orders of the tiles with indices shifted by +1
const offset = (
newTag === prevTag && result.source.index < result.destination.index
) ? 1 : 0;

const prevOrder = newIndex === 0 ?
0 : newList[offset + newIndex - 1].tags[newTag].order;
const nextOrder = newIndex === newList.length ?
1 : newList[offset + newIndex].tags[newTag].order;
const indexBefore = offset + newIndex - 1;
const indexAfter = offset + newIndex;

const prevOrder = indexBefore < 0 ?
0 : newList[indexBefore].tags[newTag].order;
const nextOrder = indexAfter >= newList.length ?
1 : newList[indexAfter].tags[newTag].order;

newOrder = {
order: (prevOrder + nextOrder) / 2.0,
Expand Down

0 comments on commit c7afaed

Please sign in to comment.