Summary:
When switching from holding one item (e.g. an iron sword) to holding another item of the same type (e.g. another iron sword), the attack speed indicator does not get reset. This is presumably intended behaviour.
However, this behaviour does not take into account the edge case of switching between two items that are of the same type but have different attack speeds. For instance, if a player has a default iron sword as well as a custom iron sword with a slower attack speed, switching from the default sword to the custom sword will not reset the attack bar.
Steps to Reproduce:
1) Ensure that the attack indicator is enabled in the video settings.
2) Obtain a normal iron sword and place it in your hotbar.
3) Run this command to obtain an iron sword with a modified attack speed of -3.9:
/give @p iron_sword{AttributeModifiers:[{AttributeName:"generic.attack_speed",Amount:-3.9,Operation:0,UUID:[I;-12123,24406,141845,-48812],Slot:mainhand,Name:"generic.attack_speed"}]} 1
4) Hit something using the default sword and wait for approximately five seconds.
5) Now, switch to holding the custom sword.
6) Divert your gaze to the attack indicator next to your crosshair or hotbar. You will see that the attack indicator will already be half full, despite having only just switched to the item you are holding.
The expected behaviour would be for the attack speed cooldown to be reset upon switching to an item with a different attack speed, regardless of whether or not the two items are of the same type.